wrapper.simulate() should be wrapped in ReactTestUtils.act()
See original GitHub issueIs your feature request related to a problem? Please describe. React 16.8 introduced act() to allow component interactions to be tested in a synchronous way.
Describe the solution you’d like
wrapper.simulate()
should be wrapped in act()
to ensure any state changes are resolved before proceeding.
Describe alternatives you’ve considered
act(() => {
wrapper.simulate();
});
Though it’s easy to forget act
.
Additional context I have a feeling this is already on your roadmap, but I couldn’t find an issue about it.
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
wrapper.simulate() should be wrapped in ReactTestUtils.act()
React 16.8 introduced act() to allow component interactions to be tested in a synchronous way. Describe the solution you'd like wrapper.simulate ...
Read more >Test Utilities - React
ReactTestUtils makes it easy to test React components in the testing ... act(). To prepare a component for assertions, wrap the code rendering...
Read more >Why do I need to wrap React/Enzyme state changes in act?
According to Enzyme's docs in most recent version mount() should be already wrapped with act() internally: If you're using React 16.8+ and ....
Read more >React Testing Library and the “not wrapped in act” Errors
I recently upgraded React and React testing library. Very happy about the upgrade. But I start to see test errors like this: In...
Read more >Why do I need to wrap React/Enzyme state changes in act?
If you're using React 16.8+ and .mount() , Enzyme will wrap apis including .simulate() , .setProps() , .setContext() , .invoke() with ReactTestUtils.act() ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mikesteele let me know if you don’t have any time . i’d be happy to put something together as well
Thanks! I’ll try to find time to contribute. I think this will be a huge improvement for users who need to force wrappers to update after simulating events to ensure that state updates are complete.