我正在尝试创建单元测试并测试组件的路由器。我想我差不多了,但我遇到了错误
'TypeError:无法读取未定义的属性'subscribe' RouterLinkWithHref'
我在网上找不到解决方案......
我的spec文件中有以下设置:
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();
})