javascript - 诗乃找不到方法 'spy'

标签 javascript backbone.js mocha.js sinon chai

我正在努力攀登将 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/

相关文章:

javascript - Backbone.js:.render() 和 .remove() 应该能够相互逆转吗?

javascript - 在集合中创建新实例后,不要在端点(主干)上执行 GET 请求

async-await - mocha async/await 测试因超时而失败

javascript - 显示弹出脚本以使其在每个浏览器 session 中仅弹出一次

javascript - 未捕获的类型错误 : Cannot read property 'name' of undefined - Reactjs

javascript - jQuery 在加载时自动调整预填充文本区域的大小

javascript - 在类似 Accordion 的选项卡上完成另一个函数后运行函数

javascript - Backbone .js : Not rendering some view

node.js - 测试express API需要本地服务器

selenium - 黑猩猩测试停止工作,抛出错误 : missing or invalid 'entry.level'