1 year ago
#388830

Gabrielle
How to mock reducers/store on react-testing-library for all tests
In my tests I normally mock each and every dispatch/selector needed for each specific test. But I have one prop on my reducers/store
that applies to almost all components. I always import it directly from the reducers/store
import { history } from 'reducers/store';
Because this is not exactly specific to each test. How can I mock that for all tests? I cannot use a beforeAll
because I am not talking about just a specific set in one component. I would like this mocked throughout all the tests in the entire application.
I already have a similar scenario for external libraries such as react-router. In this case, I only had to add a new file react-router
inside the __mocks__
folder. But I tried doing something similar to the store with
__mocks__
reducers
store.js
But that didn't work.
Since I already mock each and every dispatch and selector as needed, my store only need to have the history inside of it.
How am I able to mock this to the entire application?
reactjs
unit-testing
jestjs
react-testing-library
0 Answers
Your Answer