【发布时间】:2012-08-17 00:22:52
【问题描述】:
我正在尝试为此模块 (2) 实施测试 (1)。
我的目的是检查触发特定事件时是否提取了集合。
从我在 (2) 中的评论中可以看出,我收到了消息 Expected spy restartPolling to have been called.
该模块工作,但测试失败。有任何想法吗?
PS:
这个问题和这个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;
【问题讨论】:
标签: javascript backbone.js jasmine marionette