O'Reilly logo

Mastering Backbone.js by Abiee Echamea

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required