Also, by using the procedure described in the post you don't need to have a DOM set up. Note that the view has no knowledge of where it is supposed to be rendered on the page. It could be passed into PersonsView with an el option: new PersonsView({ collection: new Persons(), el: $("#persons") });, but instead he chooses to skip that and test on view.$. It will hold the HTML of the view in memory. This lets you write tests for the view without having to setup DOM fixtures and actually render contents to the DOM. Result: tests that are less complex to write and faster to run.
HN user
mobmad
4 karma
Posts0
Comments2
No posts found.
Integration testing Backbone.js 14 years ago
Integration testing Backbone.js 14 years ago
I think you need to read the post again.
In the first example, he:
- initializes a view
- asks the collection to fetch itself
- asserts that the VIEW now has 20 person elements, not the collection.
What this first test does is asserting that the "PersonsView" and its event binding and logic is setup correctly.The same applies for the second example where PersonsView is the object under test. In this example he asserts that an ".errors" element exists in the view if the ajax request fails. I.e. that view logic and event binding for error handling is setup correctly.
Both cases test custom code in PersonsView. The tests would probably fail if PersonsView->initialize or PersonsView->render didn't behave correctly. As far I can tell, no code test Backbone in itself.