【发布时间】:2012-01-14 00:46:19
【问题描述】:
我有一个包含模型的视图。视图侦听模型中的事件,并在事件触发后执行操作。下面是我的代码
window.Category = Backbone.Model.extend({})
window.notesDialog = Backbone.View.extend({
initialize: function() {
this.model.bind("notesFetched", this.showNotes, this);
},
showNotes: function(notes) {
//do stuffs here
}
})
我想使用 Jasmine 进行测试,下面是我的测试(不起作用)
it("should show notes", function() {
var category = new Category;
var notes_dialog = new NotesDialog({model: category})
spyOn(notes_dialog, "showNotes");
category.trigger("notesFetched", "[]");
expect(notes_dialog.showNotes).toHaveBeenCalledWith("[]");
})
有谁知道为什么上述测试不起作用?我得到的错误是“Expected spy showNotes to have been called with ['[]'] 但它从未被调用过。”
【问题讨论】:
标签: testing backbone.js jasmine