Warning: You called act(async () => ...) without await. 2 minute repro on examples/reactnavigation
See original GitHub issueDescribe the bug
I see the infamous Warning: You called act(async () => ...) without await.
after a fresh clone and install checking out the reactnavigation
example.
Expected behavior
No warnings. I thought react-native-testing-library
is supposed to wrap all async actions in act
already? I guess and use await
Steps to Reproduce
- Clone this repository:
git clone https://github.com/callstack/react-native-testing-library.git
- Move into the proper example:
cd react-native-testing-library/examples/reactnavigation
- Install packages:
npm install
(You neednpm install --legacy-peer-deps
if you are using a newer version of Node) - Run tests:
npm run test
- See warnings in test output:
console.error
Warning: You called act(async () => ...) without await. This could lead to unexpected testing behaviour, interleaving multiple act calls and mixing their scopes. You should - await act(async () => ...);
Versions
npmPackages:
@testing-library/react-native: ^7.0.0-rc.0 => 7.2.0
react: ^16.13.1 => 16.14.0
react-native: ^0.62.2 => 0.62.3
react-test-renderer: ^16.13.1 => 16.14.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top Results From Across the Web
reactjs - Any tips with the Warning: You called act(async ...
I have read several resources when it comes to writing react tests and the Warning: You called act(async () => ...) without await....
Read more >Understanding Act function | React Native Testing Library
React decides to show this error whenever it detects that async act() call has not been awaited. The exact reasons why you might...
Read more >You Probably Don't Need act() in Your React Tests
Whenever a state update is scheduled asynchronously (e.g. after a promise resolves), the test can no longer stay synchronous. Otherwise, React ...
Read more >Fix the "not wrapped in act(...)" warning - Kent C. Dodds
There are a few reasons you're getting this warning. Here's how you fix it.
Read more >Async Methods - Testing Library
findBy queries work when you expect an element to appear but the change to the DOM might not happen immediately. const button =...
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
The thing is @pierrezimmermannbam that when you actually need to use findBy (or any kind of await for async operation) twice in the same test, you’ll always have the warning.
I believe this happens when calling several times await findByText in a row though I’m not sure why. In this example the tests don’t need to be asynchronous so removing async and using getBy instead of findBy works fine and it makes the warning go away. I also think it’s a bad pattern to use findByText by default and to make all tests asynchronous when it is not necessary, so I’d recommend either changing the example so that we really need to use waitfor in the tests or using plain getByText