Reputation: 965
How can I test route.navigate
? I need to check if changed route after button click.. Here is my test:
it('Should log in and navigate to dashboard', fakeAsync(inject([LoginService, Router, Location], (authService: LoginService, router: Router, location: Location) => {
let button = fixture.debugElement.nativeElement.querySelector('#login');
spyOn(authService, 'login').and.returnValue(Observable.of(true));
button.click();
tick(1000);
expect(component.loading).toBe(false);
})));
I am using angular 2.1
Upvotes: 1
Views: 2562
Reputation: 1417
what you should do to test if router.activate
is getting called is inject a mock router, so you can spy on activate
.
take a look at this example by Joe Eames's using the Angular-provided RouterTestingModule
: https://gist.github.com/joeeames/0ddcfe8f0576bc7651ae99e6b59e81ea
Upvotes: 1