Testing views
Views manage the relationship between data (such as, models or collections) and the user interactions (DOM). In the case of views, you should test for the following:
- Rendering: Given a model or collection, you should verify that the output HTML is the right one
- Events: This verifies that the DOM events are handled correctly
- Model changes: If the model changes something, the view should be in sync
For this example, we are going to test the ContactForm
view; the responsibility of this view is to show a form to the user and then get the user input to update a model.
When making test on views, it is recommended to use a fake model and not the original Contact
model. The main reason for this is to isolate the ContactView
object so that if ...
Get Mastering Backbone.js now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.