From the course: Angular Essential Training
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Unit testing with dependency injection - Angular Tutorial
From the course: Angular Essential Training
Unit testing with dependency injection
- [Instructor] Earlier in this course, we looked at how you run an existing suite of unit tests in a project, as well as how to write tests without using dependency injection. In this video, we'll look at one common pattern for unit testing and Angular service that uses dependency injection. I talk about services and dependency injection in detail earlier in this course. For now, just think of services as a way to separate and reuse code across different parts of your application and think of dependency injection as a way for classes and functions to request dependencies from an external source rather than creating their own instances. Services and dependency injection are closely linked. You can't use one without the other. This makes them harder to test when compared to pipes or constant values. That said, we can use the built-in tools that come with Angular and Jasmine to help write our tests and manage dependencies.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.