Debugging 应为spy,但收到带有Sinon存根的函数错误消息?
我有以下测试套件:Debugging 应为spy,但收到带有Sinon存根的函数错误消息?,debugging,jasmine,sinon,spy,stubs,Debugging,Jasmine,Sinon,Spy,Stubs,我有以下测试套件: describe('rendering Bundle View', function () { beforeEach(function () { this.view = new Backbone.View(); this.renderStub = Sinon.stub(this.view, 'render', function () { this.el = document.createElement('div'
describe('rendering Bundle View', function () {
beforeEach(function () {
this.view = new Backbone.View();
this.renderStub = Sinon.stub(this.view, 'render', function () {
this.el = document.createElement('div');
return this;
});
this.view.render();
});
it('should have called render once', function () {
console.info('RENDERRRR' + (typeof this.renderStub));
expect(this.renderStub.calledOnce).toBe(true); // this passes
expect(this.renderStub).toHaveBeenCalled(); // this fails
});
});
为什么第一个expect语句通过,而第二个语句失败?第二个给出了错误消息:虽然Sinon存根实现了Spy API,但预期Spy但得到了函数,所以它应该返回Spy
我明白了。我想这是因为我使用了一个带有jasmine函数的Sinon spy,该函数期望一个jasmine spy,因此它不允许我使用Sinon expect语句
你应该对你的问题提交一个答案或者删除它,这样想帮忙的人就不会白来了。