i have a dummy Backbone.Model
App.Models.Note = Backbone.Model.extend({
default: {
title: ''
}
);
and a Backbone.View
for my model like the following:
App.Views.NoteView = Backbone.View.extend({
template: ...,
initialize: function () {
this.listenTo(this.model, "change", this.render);
this.render();
},
render: function () {
this.$el.html(this.template({
title: this.model.get("title")
}));
return this;
}
});
For testing, i use mocha.js + chai + sinon, and i have the following test
describe("App.Views.NoteView", function () {
beforeEach(function () {
this.view = new App.Views.NoteView({
el: this.$fixture,
model: new App.Models.Note()
});
}
afterEach(function () {
this.view.model.destroy();
});
it("my try 1", function () {
var mySpy1 = sinon.spy(this.view, "render");
this.view.model.set({
title: "a new Title"
});
expect(this.view.render).to.have.been.calledOnce;
});
}
What im trying to test is to spy the render
method : when i change the model attributes the render
method will be called. However, even if the render is executed normally, the test gives me error
'expected render to be called once but was called 0 times'
Any help?