Mocking NGRX store for easy testing your angular components

Mocking NGRX store for easy testing your angular components

If you want to test your angular components and you are using redux with some selectors, then you’ll surely need

@reibo/ngrx-mock-test

How to use it?

First, install as a development depenancy with npm i @reibo/ngrx-mock-test -d

Second, initialize the package and import it in your tests:

beforeEach(async(() => {
 TestBed.configureTestingModule({
   imports: [ MockStoreModule.forRoot('freature_store_reducer', initialState)],
 }).compileComponents();
}));

Final step, get the store and dispatch and action:

store = TestBed.get(Store);
store.dispatch(new MockAction({ name: "foo" }));

//if you test streams and use marble testing
const inputStream = m.hot('-a-b-a', stream);
store.dispatch(new MockStream(inputStream));

Example on stackblitz

Support and star that https://github.com/reibo/ngrx-mock-test

 

Enjoy!

Related Posts