我正在尝试为此模块 (2) 实施测试 (1)。
我的目的是检查在触发特定事件时是否获取了集合。
正如您从我在 (2) 中的评论中看到的那样,我收到消息 Error: Expected a spy, but got Function.
The module works but the test failed。有任何想法吗?
(1)
// jasmine test module
describe('When onGivePoints is fired', function () {
beforeEach(function () {
spyOn(this.view.collection, 'restartPolling').andCallThrough();
app.vent.trigger('onGivePoints');
});
it('the board collection should be fetched', function () {
expect(this.view.collection.restartPolling).toHaveBeenCalled();
// Error: Expected a spy, but got Function.
});
});
(2)
// model view module
return Marionette.CompositeView.extend({
initialize: function () {
this.collection = new UserBoardCollection();
this.collection.startPolling();
app.vent.on('onGivePoints', this.collection.restartPolling);
},
// other code
});