I'm trying to create a unit test and test the router of a component. I think I'm nearly there but I run into the error
'TypeError: Cannot read property 'subscribe' of undefined at new RouterLinkWithHref'
and I did not find the solution on the web...
I have the following setup in my spec file:
describe('TestOverviewComponent', () => {
let comp: TestOverviewComponent;
let fixture: ComponentFixture<TestOverviewComponent>;
let createEl: DebugElement;
let routerStub;
beforeEach(async(() => {
routerStub = {
navigate: jasmine.createSpy('navigate'),
routerState: {}
};
TestBed.configureTestingModule({
declarations: [], // declare the test component
imports: [
NgReduxTestingModule,
HttpClientTestingModule,
TranslateModule.forRoot(),
NgbModule.forRoot(),
DialogSharedModule,
RouterTestingModule,
TestModule
],
providers: [
{ provide: Router, useValue: routerStub },
SessionService,
Logger,
StorageService,
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TestOverviewComponent);
comp = fixture.componentInstance;
createEl = fixture.debugElement.query(By.css('.btn-primary'));
comp.paginationFilter.page = 1;
comp.paginationFilter.pageSize = 10;
fixture.detectChanges();
});
it('should be created', () => {
expect(comp).toBeTruthy();
})