我正在尝试为此模块 (2) 实施测试 (1)。
我的目的是检查在触发特定事件时是否获取了集合。
正如您从我在 (2) 中的评论中看到的那样,我收到消息 Expected spy restartPolling to have been called.
The module works but the test failed。有任何想法吗?
PS:
This question is related to this one Expected a spy, but got Function
(1)
// jasmine test module
describe('When onGivePoints is fired', function () {
beforeEach(function () {
spyOn(UsersBoardCollection.prototype, 'restartPolling').andCallThrough();
app.vent.trigger('onGivePoints');
});
it('the board collection should be fetched', function () {
expect(UsersBoardCollection.prototype.restartPolling).toHaveBeenCalled();
// Expected spy restartPolling to have been called.
});
});
(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
});
(3)
// polling module
var poller = {
restartPolling: function () {
this.stopPolling();
this.startPolling(options);
},
// other code
};
(4)
var UsersBoardCollection = Backbone.Collection.extend({
// some code
});
_.extend(UsersBoardCollection.prototype, poller);
return UsersBoardCollection;