Auth Service Fake and Common Testing Providers

We need to implement an AuthServiceFake so that our unit tests pass and use a pattern similar to commonTestingModules mentioned in Chapter 7, Create a Router-First Line-of-Business App, to conveniently provider this fake across our spec files.

To ensure that our fake will have the same public functions and properties as the actual AuthService, let's first start with creating an interface:

  1. Add IAuthService to auth.service.ts
src/app/auth/auth.service.tsexport interface IAuthService {  authStatus: BehaviorSubject<IAuthStatus>  login(email: string, password: string): Observable<IAuthStatus>  logout()  getToken(): string}
  1. Make sure AuthService implements the interface
  2. Export defaultAuthStatus

Get Angular 6 for Enterprise-Ready Web Applications 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.