1
我试图在我的测试中模拟路由器。我跟着指令一步步在this answer给出,但我仍然得到错误如何正确模拟路由器?
“不能读取属性‘’空的”出口
这是我的尝试:
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule.withRoutes([
{path:'profile/login',component:ProfileLoginComponent}]
)],
declarations: [ ProfileLoginComponent ],
providers: [
FormBuilder,AuthModel
],
schemas: [NO_ERRORS_SCHEMA]
})
.overrideComponent(ProfileLoginComponent, {
set: {
providers: [
{provide: AuthModel, useClass: MockAuthModel}
],
}
})
.compileComponents();
}));
如果我在模板中删除routerLink和routerLinkActive的代码,那么测试用例可以很好地工作。我哪里错了?
它看起来像你给的路线导航到一个叫出口,但是角度不能找到它。我无法在你的路线中看到它......你有更多的路线定义在别的地方吗? – JayDeeEss
@JayDeeEss我跑了一个完整的项目搜索。我没有任何名为'网点'的东西。只有我能找到的东西是 –
SanjuAus
好的,你可以发布你的代码在哪里导航到你的组件......无论是编程或在HTML – JayDeeEss