onClearSearch() {
this.store$.dispatch(some action);
}
尝试对组件进行单元测试并触发存储调度不起作用。我的组件测试如下所示:
let store: MockStore<State>;
beforeEach(waitForAsync(() => {
TestBed.configureTestModule({
...
providers: [
SearchStoreEffects,
provideMockActions(() => actions$),
provideMockStore({initialState, selectors: [...]})
],
...
}).compileComponents();
...
store = TestBed.inject(MockStore);
fixture.detectChanges();
}));
it('should clear search value', () => {
const storeSpy = spyOn(store, 'dispatch').and.callThrough();
component.onClearSearch();
fixture.detectChanges();
expect(storeSpy).toHaveBeenCalledTimes(1);
});