Chapter 10: Writing Unit Tests in Angular with Jest
"It works on my machine…" is a phrase that won't lose its beauty with time. It is a shield for many engineers and a nightmare for the QAs. But honestly, what's a better way than writing tests for your application's robustness, right? And when it comes to writing unit tests, my personal favorite is Jest. That is because it is super fast, lightweight, and has an easy API to write tests. More importantly, it is faster than the Karma and Jasmine setup that comes out of the box with Angular. In this chapter, you'll learn how to configure Jest with Angular to run these tests in parallel. You'll learn how to test components, services, and pipes with Jest. You'll also learn how to mock dependencies for these tests.
In this chapter, we're going to cover the following recipes:
- Setting up unit tests in Angular with Jest
- Providing global mocks for Jest
- Mocking services using...