我正在使用 SinonJS 来测试我的 Controller 是否在我的 View 中调用方法。我想测试是否使用 testSeat
的值调用了 addSeat
方法。我最大的努力是下面的代码,但我收到了一个错误。我希望能够在不将我的 View 模块带入我的测试中的情况下进行测试。这可能吗?
describe('Adding a seat', function() {
view1Spy = {
addSeat: sinon.spy(),
render: sinon.spy()
};
beforeEach(function() {
newSeat = seatingChartController.addSeat(3, 4);
seatingChartController.registerView(view1Spy);
});
it('Calls addSeat on each view with the added seat', function() {
expect(view1Spy.addSeat).to.be.calledWith(newSeat);
});
}
编辑:
这是错误:
1) Seating Chart Controller Adding a seat Calls addSeat on each view with the added seat
Failure/Error: 'undefined' is not a function (evaluating 'expect(view1Spy.addSeat).to.be.calledWith(newSeat)'
最佳答案
看起来在这种情况下你会想要这样的东西:
view1Spy = {addSeat: sinon.spy()};
// ...
expect(view1Spy.addSeat.calledWith(newSeat)).to.be.true;
关于javascript - 在 Sinon.js spy 上调用的测试方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29566600/