
Angular Cookbook
By :

In the previous recipe, we learned how to set up Jest for Angular unit tests. There might be some scenarios in which you'd want to use a browser API that might not be part of your actual Angular code; for instance, using localStorage
or alert()
. In such cases, we need to provide some global mocks for the functions we want to return mock values from. This is so that we can perform tests involving them as well. In this recipe, you'll learn how to provide global mocks to Jest.
The project for this recipe resides in chapter10/start_here/providing-global-mocks-for-jest
. Perform the following steps:
npm install
to install the dependencies of the project. ng serve -o
. This should open the app in a new browser tab. The app should appear as follows:
Figure 10.4 – The providing-global-mocks-for-jest...