question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use async act in render (and all other helpers really)

See original GitHub issue

Describe 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:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
thymikeecommented, Apr 17, 2020

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 with act warnings.

1reaction
nielskrijgercommented, Nov 1, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found