Last active
January 8, 2019 18:35
-
-
Save gparlakov/146797945ae1d2f78de0d65e533a4d69 to your computer and use it in GitHub Desktop.
@Medium article FlushMicrotasks the Service and the Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class AuthService { | |
getUser(): Promise<User> { | |
// probably make a xhr but we'll just | |
return Promise.resolve(User.Empty); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class HelloComponent { | |
// ...omitted for brevity | |
login() { | |
this.auth.getUser().then(u => { | |
if(u === User.Empty) { | |
this.router.navigate('/login') | |
} | |
}) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('should redirect to login if getUser returns the empty user', () => { | |
// given | |
// setup the empty user | |
auth.getUser.and.returnValue(Promise.resolve(User.Empty)); | |
// when | |
comp.login(); | |
// then | |
expect(router.navigate).toHaveBeenCalledWith('/login'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment