Reader small image

You're reading from  Angular 6 for Enterprise-Ready Web Applications

Product typeBook
Published inMay 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781786462909
Edition1st Edition
Languages
Right arrow
Author (1)
Doguhan Uluca
Doguhan Uluca
author image
Doguhan Uluca

Doguhan Uluca is a Principal Fellow at Excella in Washington, D.C., where he leads strategic initiatives and delivers critical systems. He has technical expertise in usability, mobility, performance, scalability, cybersecurity, and architecture. He is the author of the Angular for Enterprise Application Development books, has spoken at over 30 conferences, and is an Angular GDE Alumni. Doguhan has delivered solutions for Silicon Valley startups, Fortune 50 companies, and the U.S. Federal Government, and he is passionate about contributing to open-source projects and teaching.
Read more about Doguhan Uluca

Right arrow

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.ts

export 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 for reuse
src/app/auth/auth.service.ts

export
const defaultAuthStatus = {
isAuthenticated: false,
userRole: Role.None,
...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Angular 6 for Enterprise-Ready Web Applications
Published in: May 2018Publisher: PacktISBN-13: 9781786462909

Author (1)

author image
Doguhan Uluca

Doguhan Uluca is a Principal Fellow at Excella in Washington, D.C., where he leads strategic initiatives and delivers critical systems. He has technical expertise in usability, mobility, performance, scalability, cybersecurity, and architecture. He is the author of the Angular for Enterprise Application Development books, has spoken at over 30 conferences, and is an Angular GDE Alumni. Doguhan has delivered solutions for Silicon Valley startups, Fortune 50 companies, and the U.S. Federal Government, and he is passionate about contributing to open-source projects and teaching.
Read more about Doguhan Uluca