我正在使用SinonJS测试我的控制器在我的视图中调用方法。我想测试使用值addSeat
调用testSeat
方法。我的最大努力是在下面的代码中,但我收到一个错误。我希望能够在没有将我的视图模块带入我的测试的情况下进行测试。这可能吗?
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)'
答案 0 :(得分:3)
看起来在这种情况下你需要类似的东西:
view1Spy = {addSeat: sinon.spy()};
// ...
expect(view1Spy.addSeat.calledWith(newSeat)).to.be.true;