【发布时间】:2016-09-23 08:31:44
【问题描述】:
我正在尝试为此模块 (2) 实施测试 (1)。
我的目的是检查触发特定事件时是否提取了集合。
从我在 (2) 中的评论中可以看出,我收到了消息 Error: Expected a spy, but got Function.
该模块工作,但测试失败。有任何想法吗?
(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
});
【问题讨论】:
-
没有足够的代码来查看发生了什么。请不仅仅包括单个函数 - 至少包括函数所属的对象定义,以及实例化对象的代码。
-
@DerickBailey 感谢您抽出宝贵时间。我用模式代码更新了我的问题。
-
我使用 QUnit 而不是 Jasmine,但您对 app.vent.trigger 的调用不应该在“it”方法中而不是 beforeEach 中吗?
-
@codemonkey,@DerickBailey,实际上我得到了一个不同的错误:
Expected a spy, but got Function。我更新了我的问题。
标签: javascript backbone.js jasmine marionette