诗乃找不到方法'间谍'

Eri*_*rik 5 javascript mocha.js backbone.js sinon chai

我试图通过使用require.js/mocha/chai/sinon和骨干应用程序来攀登学习曲线.当我运行此测试时:

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();
            });
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

我找到TypeError: Object #<Object> has no method 'spy' 了定义helloSpy的行.为什么?请注意,第一次测试通过.

这是完整的项目:

https://github.com/ErikEvenson/spa-testing-study/tree/bcc5b71b3b6f8b24f7e8d01673b50682498ee1b2.

注意使用该特定提交.

Eri*_*rik 7

这里的问题结果是,sinon的bower存储库不能用于此问题.Sinon必须先建造,然后bower install sinon将Sinon.JS回购拉下来.使用bower install sinonjs而不是bower install sinon工作,但提供早期版本号.