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