我正在努力攀登将 require.js/mocha/chai/sinon 与 Backbone 应用程序结合使用的学习曲线。当我运行 this test :
define([
"chai",
"sinon"
], function(chai, sinon){
var expect = chai.expect;
describe("Trying out the test libraries", function(){
describe("Chai", function(){
it("should be equal using 'expect'", function(){
expect(hello()).to.equal("Hello World");
});
});
describe("Sinon.JS", function(){
it("should report spy called", function(){
var helloSpy = sinon.spy(window, "hello");
expect(helloSpy.called).to.be.false;
hello();
expect(helloSpy.called).to.be.true;
hello.restore();
});
});
});
});
我得到 TypeError: Object #<Object> has no method 'spy'
on the line where helloSpy is defined .为什么?请注意,第一个测试通过了。
这是完整的项目:
https://github.com/ErikEvenson/spa-testing-study/tree/bcc5b71b3b6f8b24f7e8d01673b50682498ee1b2 .
小心使用那个特定的提交。
最佳答案
这里的问题原来是 sinon 的 bower 存储库无法使用,因为 this issue .必须先构建 Sinon,然后执行 bower install sinon
只会拉下 Sinon.JS 存储库。使用 bower install sinonjs
而不是 bower install sinon
可以工作,但会提供更早的版本号。
关于javascript - 诗乃找不到方法 'spy',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18391301/