Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save kimjoar/2556686 to your computer and use it in GitHub Desktop.
integration testing Backbone.js
it("should show error message when pagination fails", function() {
// ajax responses
var response = readFixtures("responses/persons.json");
var errorResponse = readFixtures("responses/errors.json");
// create our initial view
var view = new PersonsView({ collection: new Persons() });
view.render(); // show header and other static stuff
// mock out all requests
fakeResponse(response, headers, function() {
view.collection.fetch(); // trigger Ajax request
});
// now we have set up our initial state, and can go on to doing things
// in the view.
// we ensure that errors are not present
expect(view.$('.errors')).not.toExist();
// we set up an error response ...
fakeResponse(errorResponse, { statusCode: 503 }, function() {
// ... and we trigger the error by clicking the next button
// (in our view we listen for the click event and start the
// pagination process)
view.$('a.more').click();
});
// ensure that errors are present
expect(view.$('.errors')).toExist();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment