Skip to content

Instantly share code, notes, and snippets.

@rmw
Created September 30, 2011 02:59
Show Gist options
  • Save rmw/1252530 to your computer and use it in GitHub Desktop.
Save rmw/1252530 to your computer and use it in GitHub Desktop.
Stubbing Backbone.js's fetch method with Jasmine & Sinon.js
beforeEach(function() {
var self = this;
//contacts
this.contacts = new App.Collections.Contacts();
_.each(this.fixtures.Contacts.valid, function(c) {
self.contacts.add(new Contact(c));
});
this.contactsCollectionStub =
sinon.stub(App.Collections, 'Contacts')
.returns(this.contacts);
this.contactsFetchStub =
sinon.stub(this.contacts, 'fetch')
.yieldsTo('success', this.contacts);
});
afterEach(function() {
this.contactsCollectionStub.restore();
this.contactsFetchStub.restore();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment