Accepted answer

After reading I decided to mock the useReducer as the dispatches cause state updates in the useEffect hook. After that it worked. I now mock the reducer initial state.

const dispatch = jest.fn();
const useReducerSpy = jest.spyOn(React, 'useReducer');
useReducerSpy.mockImplementation((init: any) => [MY_CONTEXT_MOCK, dispatch]);

and my test looks like

it('should render', async () => {
  const { result } = renderHook(useMyContext, { wrapper: bySlugWrapper });

Related Query

More Query from same tag