Unit test for DoctorListComponent

The unit tests illustrated next for DoctorListComponent focus on the following aspects:

  • Use Spy on one or more Service APIs: Using Spy in place of a fake object, recall that in the previous section, a fake object such as authServiceStub was used in place of AuthService. Also recall that spy allows the invocation of the actual service. However, only the method which is spied on is replaced to return the predefined result. In the following code sample, two APIs, getDoctorsBySpeciality and getDoctorsCount, are spied on. Note the value returned in both the cases. SpyOn, when invoked on getDoctorsBySpeciality, returns an observable on the predefined object (array of doctors) as shown further. SpyOn, when invoked ...

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.