小编Sal*_*ikh的帖子

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

我的模板包含

<a [routerLink]="['/my-profile']" routerLinkActive="active">
    <i class="icon-user"></i>{{ 'MY_PROFILE' | translate }}
</a>
Run Code Online (Sandbox Code Playgroud)

错误是因为routerLink和routerLinkActive指令.

单元测试文件.

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

unit-testing karma-jasmine angular

7
推荐指数
2
解决办法
1万
查看次数

标签 统计

angular ×1

karma-jasmine ×1

unit-testing ×1