Using spies on an injected service in a unit test
While you can provide stubs for your services in the unit tests with Jest, sometimes, it might feel like an overhead creating a mock for every new service. Let's suppose that if the service's usage is limited to one test file, it might make more sense to just use spies on the actual injected service. In this recipe, that's exactly what we're going to do.
Getting ready
The project for this recipe resides in chapter10/start_here/using-spies-on-injected-service
.
- Open the project in Visual Studio Code.
- Open the Terminal and run
npm install
to install the dependencies of the project. - Once done, run
npm run test
.
This should run the unit tests on the console using Jest. You should see something similar to the following output:
Now that we have the tests running locally...