full example on stackblitz or in the src folder
npm i @reibo/ngrx-mock-test -d
, or if you preffer yarn yarn add @reibo/ngrx-mock-test -d
The purpose of this mock store is to use it on feature based stores.
You will provide the data in the store like you decide, so it is ideal to test with mocked data.
In the MockStoreModule in your Testbed imports with your feature name and an initial state.
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ MockStoreModule.forRoot('feature_name', initialState)],
...
}).compileComponents();
}));
Next get store out of the testbed
store = TestBed.get(Store);
Change the state in your test during testing with the mock
store.dispatch(new MockAction({ name: "foo" }));
Do you like to work with streams and you us marble testing?
Try out:
const inputStream = m.hot('-a-b-a', stream);
store.dispatch(new MockStream(inputStream));