【发布时间】:2015-04-10 16:42:35
【问题描述】:
我正在使用 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)'
【问题讨论】:
-
错误是什么?如果我们不知道,那就不好了:)
-
@Andy 我刚刚添加了它。谢谢。
-
您使用的
expect模块是什么—— chai?
标签: javascript sinon