【发布时间】:2019-09-10 10:27:17
【问题描述】:
我正在为 Angular 应用程序运行单元测试,如果导航在 Angular 应用程序中正常工作,我想进行单元测试。
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
})
【问题讨论】:
-
查看有关测试路由器的 Angular 文档。 angular.io/guide/testing#routing-component。一般的策略是使用 jasmine 创建一个间谍对象,并在测试中使用该间谍对象。
-
@Karthik_personal 检查答案
标签: angular unit-testing router navigateurl