Dependencies and Unit Tests
Dependencies are one of the most widely used mechanisms in AngularJS. You see them everywhere, from dependency injection to global services. This can present a problem when it comes to unit tests because you don’t really want to have to test the full functionality of the dependency within the unit test. Instead, you will want to get the dependency and control it with your own mock objects and services.
There are four methods for controlling the dependency injection:
■ Create your own instance of the dependency using the new operator.
■ Create the dependency as a global object you can look up anywhere.
■ Ask a registry for it. This option requires that you have access to the registry as well, which means also placing ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access