我正在为角度应用程序运行单元测试,我想对导航在角度应用程序中是否正常工作进行单元测试。
if (this.customer.length == 0) {
this.router.navigate(['/nocustomer']);
}
以及这个的单元测试
it(`should navigate to nocustomer`,()=>{
component.customers.length=0;
//what must be written here to check this
})
有时,我动态地放置其他参数来调用导航。因此,只期望我在测试中使用的路径:
...
test('Navigate to /nextPage.', inject([Router], (mockRouter: Router) => {
const spy = spyOn(mockRouter, 'navigate').and.stub();
component.goToNextPageMethod();
expect(spy.calls.first().args[0]).toContain('/nextPage');
}));
...
参考:https://semaphoreci.com/community/tutorials/testing-routes-in-angular-2 https://semaphoreci.com/community/tutorials/testing-routes-in-angular-2
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)