From the course: Angular: Testing and Debugging

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Fixing injection dependency errors

Fixing injection dependency errors - Angular Tutorial

From the course: Angular: Testing and Debugging

Start my 1-month free trial

Fixing injection dependency errors

- [Instructor] In the last video we use the NPM run test command to run our suite of unit tests, and we got two errors, one for the web storage service and the other in user list component. These tests failed because of a no injection error. This is a fancy way of saying the code we want to test has a dependency on another file, and we need to inject that dependency into our test code. But here's where things get tricky, unit tests check code in isolation. We break this rule as soon as we start injecting dependencies into our tests. If the test fails, we want to know the failure happened because of something in our code and not because of an issue in the dependency itself. So instead of injecting real dependencies, we inject fake ones and mock the method calls. There are a few ways to do this, but in this context the cleanest approach is to use angulars testbed class and provide a fake service using Jasmine's spy object. I'm in the spec file for our web storage service. Angular…

Contents