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.

Warning: You called act(async () => ...) without await. 2 minute repro on examples/reactnavigation

See original GitHub issue

Describe 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

  1. Clone this repository: git clone https://github.com/callstack/react-native-testing-library.git
  2. Move into the proper example: cd react-native-testing-library/examples/reactnavigation
  3. Install packages: npm install (You need npm install --legacy-peer-deps if you are using a newer version of Node)
  4. Run tests: npm run test
  5. 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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
teves-castrocommented, Jan 19, 2022

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.

3reactions
pierrezimmermannbamcommented, Dec 6, 2021

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

Read more comments on GitHub >

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

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