Testing controllers

Controllers are more complex than test as they have more dependencies than the models, collections, and views. If you explore the code on these objects, you will see that the only dependencies that they have are Backbone and Underscore.

You can test the controllers with all its dependencies, which means that while testing the ContactEditor controller, you will be testing all the views and models attached to it as the module requires these objects.

That's not good for unit testing as you will end up with integration tests instead. If the Contact model has a defect, then ContactEditor will fail, even if it does not have any error in it.

You need to isolate the modules from the mess of other modules. Keep in mind that you should ...

Get Mastering Backbone.js now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.