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 trust your libraries as they will already have their test suites. We need a mechanism to fake the dependencies of a module.
With dependency injection, you can overwrite the require()
function, instead of loading the script that points, in order to use...