Skip to content

Instantly share code, notes, and snippets.

@p-baleine
Created September 11, 2012 23:38
Show Gist options
  • Save p-baleine/3703041 to your computer and use it in GitHub Desktop.
Save p-baleine/3703041 to your computer and use it in GitHub Desktop.
testing listener of Backbone event
describe('when add event is fired on Todos collection', function() {
before(function() {
var init = this.TodoList.prototype.initialize;
// spying event related method
this.TodoList.prototype.initialize = function() {
sinon.spy(this, 'renderOne');
init.apply(this, arguments);
};
this.todoList = new this.TodoList({ el: '#main' });
this.added = new Backbone.Model({ content: 'piyo' });
this.todoList.collection.add(this.added);
});
after(function() {
this.todoList.renderOne.restore();
});
it ('should render new TodoItem view', function() {
this.todoList.renderOne.calledOnce.should.be.ok;
this.todoList.renderOne.args[0][0].get('content').should.eql('piyo');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment