-
-
Notifications
You must be signed in to change notification settings - Fork 44
Warning: An update to Example inside a test was not wrapped in act(...). #25
Comments
I’m cool with leaving this open until a solution is available. Unfortunately for us in React Native it may take a little longer because we not only need React 16.9, but also a version of React Native that supports 16.9. I don’t necessarily suggest mocking YellowBox completely, because YellowBox can show you actual warnings in your tests just like your app would show you, but i do recommend that you can ignore certain messages in YellowBox like this So, for reference for future readers, this isn’t a bug with the testing library family of tools, we’re ready for it once it’s fixed, but let’s leave this open as a reference for anyone else who has this question in the future 👍 thanks for calling it out! |
Apologies for my late reply on this! I'm really glad to hear that you're prepared for when the updates land for the relevant packages! Thanks for the tip on the |
While @lewie9021 's fix fixes the I tried to Error logFAIL src/Example.test.js ✕ examples of some things (228ms)● examples of some things
› 1 snapshot failed. Test Suites: 1 failed, 1 total |
Hi @toumas, Have you tried the approach of simply mocking the YellowBox module ( I'm personally of the opinion that it serves no purpose in the output as it's a component that's only present in development and therefore not a concern from the user’s point of view. As mentioned previously, my understanding of the YellowBox module is simply another output stream for console.warn calls. |
Your test has two main users: the end user and the developer. It benefits the developer to know that there are YellowBox warnings, even though it doesn't benefit the end user because they shouldn't ever see it. My argument is that most of the time, YellowBox warnings should be relevant to you in your tests, unless you believe the YellowBox isn't useful in general (even during development). In that case, my suggestion would be to turn YellowBox off for your application because you don't find value in it or it isn't helping your team, otherwise you should pay attention to the YellowBox in your tests just like you would in your app. All of that said, we can't help it in this case because the issue is with React, not this library. If in the meantime that means you mock the YellowBox in your tests, that's probably fine, but I'd suggest un-mocking it once React 16.9 is released and supported by React Native. |
This is partly addressed by #50 but you'll still get some errors. Async act is only fully supported in React 16.9, and there's currently no version of React Native that officially supports React 16.9. As soon as a version does support it though, this will be good to go 👍 |
🎉 This issue has been resolved in version 4.0.8 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
I'm getting the exact same issue with the following dependencies in my
|
react-native
orexpo
: react-nativenative-testing-library
version: 3.1.1jest-preset
: native-testing-libraryreact-native
version: 0.59.2node
version: 10.13.0Relevant code or config:
What you did:
Ran the example found within the documentation that demonstrates an async state update: https://www.native-testing-library.com/docs/example.
What happened:
I get a console.error message suggesting there is a problem with the tests:
Reproduction:
See code snippet above.
Problem description:
Whenever I run the tests, I'm flooded with these
console.error
messages whenever I test components that make state changes after async logic such as network requests.Suggested solution:
I feel this is a known issue, but I've not yet seen a ticket open for it on this project. I figured it would be helpful for others to reference and track the progress.
I've attempted to Google around to see if I can find a solution, but appears to be something fundamentally wrong with the underlying library that the
*-testing-library
family uses,react-test-renderer
. This was highlighted in a react-testing-library issue and appears to have a fix on the way in React 16.9 once at least this umbrella issue is closed.Below is my current workaround:
In my Jest config file, I have a reference to a custom setup script:
In the custom setup script (setupJest.js), I have the following:
Note:
mockConsoleMethod
is used to only suppress logs that contain"test was not wrapped in act(...)"
.The text was updated successfully, but these errors were encountered: