Mocking Angular services using stubs
There’s rarely an Angular app that doesn’t have a Service created inside it. And where overall business logic is concerned, services hold a great deal, particularly when it comes to interacting with APIs. In this recipe, you’ll learn how to mock services using stubs.
Getting ready
The app that we are going to work with now resides in start/apps/chapter10/ng-test-services-stubs
inside the cloned repository:
- Open the code repository in your code editor.
- Open the terminal, navigate to the code repository directory, and run the following command to serve the project:
npm run serve ng-test-services-stubs
This should open the app in a new browser tab, and you should see the following:
Figure 10.6: The ng-test-services-stubs app running on http://localhost:4200
Now that we have the app running locally, in the next section, let’s take a look at the steps of the recipe...