【发布时间】:2013-08-25 19:47:23
【问题描述】:
我正在尝试在将 require.js/mocha/chai/sinon 与主干应用程序一起使用时攀登学习曲线。当我运行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是您所期望的吗? -
我做到了,但事实并非如此。它是一个对象,由 sinon.js 创建,但没有 spy() 方法。
-
我会看看 require.js 的设置。我只是在墙上抛出一些想法,看看有什么坚持;抱歉,我不能更具体,我对这些工具不是很熟悉。
-
我认为你是对的——我怀疑 sinon 无法找到 spy.js 所在的目录——但我不知道如何解决这个问题......跨度>
-
有没有
sinon.sinon.spy?
标签: javascript backbone.js mocha.js sinon chai