I've just updated Redux and React-redux to the latest versions (5.0.1 and 9.2.0 respectively) and a lot of my tests fail. Up until now I've used jest.spyOn like this:
const mockUseDispatch = jest.spyOn(Redux, 'useDispatch');
const mockUseSelector = jest.spyOn(Redux, 'useSelector');
This does not work anymore, as it fails with an error that useDispatch cannot be mocked. I also tried to mock them the following way:
const mockUseDispatch = jest.fn().mockReturnValue(mockDispatch);
const mockUseSelector = jest.fn();
jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
useDispatch: mockUseDispatch,
useSelector: () => mockUseSelector,
}));
But this also does not work, because with this, the mock doesn't seem to work and the component I'm testing is using the actual useDispatch from react-redux.
What is the correct way to mock these hooks?