如果getToken()返回一个值,有没有办法检查路由器是否导航到所需的页面。
onSubmit(value: Authentication){
this.authenticateService.getTokenFromServer(value).subscribe(v => {
if(this.tokenService.getToken()){
this.router.navigate([Config.videoPage]);
}
console.log(this.tokenService.getToken());
});
}
单元测试我已尝试
it('redirect to video if token set', () => {
let component = fixture.componentInstance;
let navigateSpy = spyOn((<any>component).router, 'navigate');
component.onSubmit({name: 'Abc', password: '123'});
expect(navigateSpy).toHaveBeenCalledWith(['/video']);
});