Last active
May 18, 2021 12:00
-
-
Save andreivasilache/afd1b1e372d7ca5bb8085e3ce9eb5504 to your computer and use it in GitHub Desktop.
React Jest+react-dom/test-utils wait for component to finish updating state
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
import { mount } from 'enzyme'; | |
import { act } from 'react-dom/test-utils'; | |
const waitForComponentToPaint = async wrapper => { | |
await act(async () => { | |
await new Promise(resolve => setTimeout(resolve)); | |
wrapper.update(); | |
}); | |
}; | |
describe('Lorem ipsum', () => { | |
it('waits for load', async () => { | |
const wrapper = mount(<ToBeTestedComponent/>); | |
await waitForComponentToPaint(wrapper); | |
expect(/**/).toBe(true) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment