我正在尝试为ActivatedRoute
. 这是我的测试的样子。
it("should check if subscribes are called in init", () => {
const subRouteSpy = spyOn(activatedRouteStub.paramMap, "subscribe");
component.ngOnInit();
expect(subRouteSpy).toHaveBeenCalled();
});
我的TestBed config
:
const activatedRouteStub = {
paramMap: {
subscribe() {
return of();
}
}
};
TestBed.configureTestingModule({
declarations: [HomeFilterDrawerComponent],
providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub }
],
imports: [
FormsModule,
StoreModule.forRoot(appReducers),
HttpClientTestingModule,
RouterTestingModule
]
}).compileComponents();
测试一直失败,让我Expected spy subscribe to have been called.
不确定我在这里到底做错了什么。
组件内部ngOnInit
的代码。
this.route.paramMap.subscribe(params => {
if (params["params"].slug !== undefined) {
}
});