Skip to content

Instantly share code, notes, and snippets.

@andreivasilache
Last active May 18, 2021 12:00
Show Gist options
  • Save andreivasilache/afd1b1e372d7ca5bb8085e3ce9eb5504 to your computer and use it in GitHub Desktop.
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
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