Skip to content

Instantly share code, notes, and snippets.

@gparlakov
Last active January 8, 2019 18:35
Show Gist options
  • Save gparlakov/146797945ae1d2f78de0d65e533a4d69 to your computer and use it in GitHub Desktop.
Save gparlakov/146797945ae1d2f78de0d65e533a4d69 to your computer and use it in GitHub Desktop.
@Medium article FlushMicrotasks the Service and the Component
export class AuthService {
getUser(): Promise<User> {
// probably make a xhr but we'll just
return Promise.resolve(User.Empty);
}
}
export class HelloComponent {
// ...omitted for brevity
login() {
this.auth.getUser().then(u => {
if(u === User.Empty) {
this.router.navigate('/login')
}
})
}
}
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