Created
February 2, 2024 19:48
-
-
Save Julianhm9612/2098fbe8212e103e91462380e1103ce9 to your computer and use it in GitHub Desktop.
Jest - Mock dispatch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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