Skip to content

Instantly share code, notes, and snippets.

@Julianhm9612
Created February 2, 2024 19:48
Show Gist options
  • Save Julianhm9612/2098fbe8212e103e91462380e1103ce9 to your computer and use it in GitHub Desktop.
Save Julianhm9612/2098fbe8212e103e91462380e1103ce9 to your computer and use it in GitHub Desktop.
Jest - Mock dispatch
const dispatch = jest.fn();
const state = { ... };
render(
<SomeContext.Provider value={{ state, dispatch }}>
<Component />
</SomeContext.Provider>
);
// Call a button or somtheing
expect(dispatch).toHaveBeenCalled();
expect(dispatch).toHaveBeenCalledWith({
payload: { value: 'N' },
type: 'SOME/SET_SOME'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment