I am writing test for sibebar navigation component. Each link contains routerLink
and routerLinkActive
directives. If I remove routerLinkActive
directive from all link, everything is fine, but with routerLinkActive
it gives me an error TypeError: Cannot read property 'subscribe' of undefined at new RouterLinkWithHref
Here is an example of my links in html:
<li>
<a class="tab" [routerLink]="['dashboard']" [routerLinkActive]="active">
Dashboard
</a>
</li>
My test file:
describe('SideBarComponent', () => {
let component: SideBarComponent;
let fixture: ComponentFixture<SideBarComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule.withRoutes(appRoutes)
],
declarations: [SideBarComponent],
providers: [
{
provide: UserService, useClass: UserServiceMock
},
{
provide: Router, useClass: RouterStub
},
{
provide: ActivatedRoute, useClass: ActivatedRouteStub
}
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SideBarComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
Aucun commentaire:
Enregistrer un commentaire