-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

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 that 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 app that we are going to work with now resides in start/apps/chapter10/ng-jest-global-mocks
inside the cloned repository:
npm run serve ng-jest-global-mocks
This should open the app in a new browser tab, and you should see the following...