单元测试订阅功能

时间:2017-11-27 09:33:49

标签: angular unit-testing angular-router

如果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']);
  });

0 个答案:

没有答案