Skip to content

Instantly share code, notes, and snippets.

@leviwilson
Created November 7, 2011 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leviwilson/1345408 to your computer and use it in GitHub Desktop.
Save leviwilson/1345408 to your computer and use it in GitHub Desktop.
Jasmine Spy Misuse
describe('Backbone View Example', function () {
beforeEach(function () {
this.collection = jasmine.createSpyObj(MyModels, ['bind']);
this.view = new MyView({collection: this.collection});
});
it('should render itself when the collection changes', function () {
expect(this.collection.bind)
.toHaveBeenCalledWith(['change', this.view.render]);
});
it('should render itself when the collection changes v2', function () {
var args = this.collection.bind.mostRecentCall.args;
expect(args[0]).toEqual('change');
expect(args[1]).toEqual(this.view.render);
});
});
(function($) {
MyModel = Backbone.Model.extend({});
MyModels = Backbone.Collection.extend({
model: MyModel
});
MyView = Backbone.View.extend({
initialize: function () {
_.bindAll(this, 'render');
this.collection.bind('change', this.render);
},
render: function () {
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment