如何测试主干视图是否触发了事件,然后模型已更改?
问问题
758 次
1 回答
3
如果您的视图正在生成el
自身,您可以通过视图的$el
.
describe("my test", function(){
var MyModel = Backbone.Model.extend({});
var MyView = Backbone.View.extend({
events: {
"click a": "aClicked"
},
aClicked: function(e){
e.preventDefault();
this.model.set({foo: "bar"});
},
render: function(){
this.$el.html("<a href='#foo' id='fooLink'>foo</a>");
}
});
var myModel;
beforeEach(function(){
myModel = new MyModel();
var myView = new MyView({
model: myModel
});
myView.render();
// this will "click" the link
myView.$("#fooLink").trigger("click");
})
it("should do that stuff", function(){
expect(myModel.get("foo")).toBe("bar");
});
});
于 2012-04-13T12:56:05.837 回答