Skip to content

Instantly share code, notes, and snippets.

@kimjoar
Created April 30, 2012 08:48
Show Gist options
  • Select an option

  • Save kimjoar/2556673 to your computer and use it in GitHub Desktop.

Select an option

Save kimjoar/2556673 to your computer and use it in GitHub Desktop.
Example of simple integration test using Backbone.js
it("should list all persons in response", function() {
// fetch an Ajax response
var response = readFixtures("responses/persons.json");
var options = {}; // no additional options for the Ajax request
// create our view, sending in an empty collection
var view = new PersonsView({ collection: new Persons() });
view.render(); // show header and other static stuff
// mock out all requests (this is our core test abstraction),
// i.e. what this function does is responding to all Ajax requests in
// the callback with the same response and with the same options.
// Thus, when `fakeResponse` is finished, all Ajax requests will have
// responded, and as we listen for finished Ajax requests in our view,
// we will then have properly set up our PersonsView.
fakeResponse(response, options, function() {
view.collection.fetch(); // trigger Ajax request
});
// ensure that all persons are present
expect(view.$('.persons li').length).toEqual(20);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment