Unit testing a component with one or more dependencies

Many of the components in an Angular app, which are required to interact with the server for performing data operations, depend upon the delegate services. As a best practice, Angular recommends that the components should delegate the data processing tasks to the external or delegate services. In this section, we will learn about doing unit tests for such components. In such scenarios, it is recommended to use a test double for the dependent service, primarily because the intention is to test the component and not the services.

Let's take a look at a scenario where a component depends upon an authentication service to determine whether a user is logged in or not, and displays an appropriate ...

Get Building Web Apps with Spring 5 and Angular now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.