Use async act in render (and all other helpers really)
See original GitHub issueDescribe the Feature
Since React and react-test-renderer
16.9.0 we have async act. This would be super helpful in the tests to remove all the act warnings and make a few tests pass that are failing otherwise
Possible Implementations
The easiest option would just be to update react-test-renderer
and then making all act calls async by default. However, I’m not sure how that would work with downwards compatibility…
Related Issues
Would fix #176 and #200 which are both results of async act not being available
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:7 (3 by maintainers)
Top Results From Across the Web
React's sync and async `act`. One challenge of ... - Medium
React provides a helper called act() that makes sure all updates related to these “units” have been processed and applied to the DOM...
Read more >Testing async stuff in React components with Jest and react ...
Solution. When using plain react-dom/test-utils or react-test-renderer , wrap each and every state change in your component with an act().
Read more >Why does this official React testing recipe using await/act ...
It seems like act chooses to use this recursivelyFlushAsyncActWork simply because the callback has the signature of being "thenable", ...
Read more >You Probably Don't Need act() in Your React Tests
Since React state updates are asynchronous, React has to know when to do all of these things. That is why act() is necessary....
Read more >A Complete Guide to Testing React Hooks - Toptal
This is because the state update in useStaleRefresh hook happens outside act(). To make sure DOM updates are processed timely, React recommends you...
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 FreeTop 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
Top GitHub Comments
Using async act won’t magically fix your problems, because rendering is sync anyway and we won’t
await
your render. Please see this issue: https://github.com/callstack/react-native-testing-library/issues/250 and this blog post https://kentcdodds.com/blog/fix-the-not-wrapped-in-act-warning to learn how to deal withact
warnings.I’m working on a RN 0.59 project; updating 0.6X is a big change and we’re tackling it one step at a time. In our proces to ditch Enzyme we started migrating to this library. For us the main reason to use this library over https://www.npmjs.com/package/@testing-library/react-native was @testing-library/react-native requires async act which is only available in the newest RN versions.
I’m really happy to see wanting to support both for now has been on your mind 👍 Having a more gradual upgrade path is really helping us out.