我在下面有一个绑定到按钮单击的函数。TeaserView 类下面的代码。
addCard: function() {
if(!this.model.get("loggedIn")){
Backbone.pubSub.trigger("Signup");
return;
}
this.showAddCardDialog();
}
这是我的测试方法
it("Should trigger signup event when clicked and not logged in", function(){
Backbone.pubSub = _.extend({}, Backbone.Events);
signupCallback = jasmine.createSpy("Signup");
//Backbone.pubSub.on("Signup", signupCallback);
teaserView = new TeaserView({
el: "#teaser",
model: this.model //was created in setup call
});
$("#addCard").trigger("click");
expect(signupCallback).toHaveBeenCalled();
});
但是我检查是否调用了 Backbone.pubSub 自定义事件的测试失败了。如何正确测试对此事件的侦听?