Created
May 17, 2019 13:48
-
-
Save joernb/a9e9e0dfd0dd9aaf76865b8c3fab3e52 to your computer and use it in GitHub Desktop.
Mock useState for async act
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
jest.mock('react', () => { | |
const react = jest.requireActual('react'); | |
const reactTestingLibrary = jest.requireActual('react-testing-library'); | |
return { | |
...react, | |
useState: initial => { | |
const [state, setState] = react.useState(initial); | |
return [ | |
state, | |
newState => reactTestingLibrary.act(() => setState(newState)) | |
]; | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment