我有以下测试套件:
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
});
});
为什么第一个期望语句通过但第二个失败?第二个给出错误消息:expected Spy but got Function 即使 Sinon 存根实现了 spy API 所以它应该返回一个 spy??