Created
April 30, 2012 08:48
-
-
Save kimjoar/2556673 to your computer and use it in GitHub Desktop.
Example of simple integration test using Backbone.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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