-
Notifications
You must be signed in to change notification settings - Fork 273
Async data load with useEffect
still triggers act
warning
#200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Gonna have a look tomorrow, thanks for the report! |
Unfortunately, there's nothing on our side we can do. This is a
However, personally, I try to ignore these warnings 🤷♂. Also, please use |
I added this to my jest setup file, maybe someone find it useful: const originalConsoleError = console.error;
console.error = (...args) => {
if (
!args[0].startsWith(
'Warning: An update to %s inside a test was not wrapped in act(...).',
)
) {
originalConsoleError(...args);
}
}; |
Thanks @neiker, appreciated! |
Versions
Description
I'm attempting to test asynchronous data loads within
useEffect
, and I'm getting that old React "An update to [your component] inside a test was not wrapped in act(...)"I see in #111 that changes were merged related to adding
act
to various RNTL calls, but that doesn't seem to address this case.I finally dug through the master React issue on the
act
warnings, and my main takeaways are:useFakeTimers
andrunAllTimers
—this is the way Facebook does it and it should work.act
has been updated to supportasync
/await
, and so you will be able to do all your stuff in the test insideact
, and assert outside of it. Just not released yet.I tried the "the way Facebook does it" fix and it doesn't seem to work (see reproducible demo below). Do you know of a way to get the test to correctly run this code through
act
such that I don't get the warning?Reproducible Demo
https://github.com/CodingItWrong/TestingRNHooks
The text was updated successfully, but these errors were encountered: