Could you help me mock the Store? I saw this and this question having a slightly different error. I use storage in one of my services, where I use dispatching, select and retrieve storage methods. I mocked the Store after the @noelmace suggestion and used the following dispatcher, gear and state, creating the repository:
export class ObservableMock implements Observer<any> { closed?: boolean = false; // inherited from Observer nextVal: any = ''; // variable I made up constructor() { } next = (value: any): void => { this.nextVal = value; }; error = (err: any): void => { console.error(err); }; complete = (): void => { this.closed = true; } } let _reducer: ObservableMock = new ObservableMock(); let _dispatcher: ObservableMock = new ObservableMock(); let state$: Observable<any> = new Observable<any>();
So my Mockstore class is as follows:
export class MockStore<T> extends Store<T> {
However, when I try to define my service in a test as follows, it says
TypeError: _store.select is not a function
This error is caused by the following line in the TestedService constructor:
constructor(private _store: Store<TabStore>) { let tabStore: Observable<TabStore> = _store.select<TabStore>('myReducer');| }
Here is my test:
beforeEach(() => { TestBed.configureTestingModule({ imports: [ // StoreModule.provideStore({myReducer: myReducer}), ], providers: [ {provide: Store, useClass: MockStore}, { provide: TestedService, useFactory: (tabStore: Store<TabStore>): TestedService=> { return new TestedService(myStore); }, deps: [Store] } ] }); });
Commenting on imports does not help. Does anyone have any idea what's wrong with ridicule?
source share