I\'ve run into missing
messages in other unit tests, but just to have a nice isolated example, I created an AuthGuard that checks if a user is
If you want to test the router without mocking it you can just inject it into your test and then spy directly on the navigate method there. The .and.stub()
will make it so the call doesn't do anything.
describe('something that navigates', () => {
it('should navigate', inject([Router], (router: Router) => {
spyOn(router, 'navigate').and.stub();
expect(authGuardService.canActivate({}, {})).toBe(false);
expect(router.navigate).toHaveBeenCalledWith(['/login']);
}));
});