加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular 2单元测试:无法读取未定义的属性“root”

发布时间:2020-12-17 06:53:35 所属栏目:安全 来源:网络整理
导读:我的模板包含 a [routerLink]="['/my-profile']" routerLinkActive="active" i class="icon-user"/i{{ 'MY_PROFILE' | translate }}/a 错误是因为routerLink和routerLinkActive指令. 单元测试文件. TestBed.configureTestingModule({ imports: [ Multilingua
我的模板包含

<a [routerLink]="['/my-profile']" routerLinkActive="active">
    <i class="icon-user"></i>{{ 'MY_PROFILE' | translate }}
</a>

错误是因为routerLink和routerLinkActive指令.

单元测试文件.

TestBed.configureTestingModule({
    imports: [
        MultilingualModule,CommonModule,RouterTestingModule.withRoutes([
            { path: 'my-profile',component: MockComponent },{ path: 'change-password',])
    ],schemas: [ NO_ERRORS_SCHEMA ],declarations: [TopNavigationBarComponent,TestComponent,MockComponent],providers: [
        { provide: LoginService,useValue: MockLoginService },{ provide: Router,useClass: RouterStub }
    ]
});

解决方法

问题是你实际上是在覆盖路由器来进行测试,这使得它破坏了routerLink.
你可以在这里看到如何对测试路线进行单元测试的一个很好的解释: Angular 2 Final Release Router Unit Test

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读