CodePark/ questions / Async UI & act()
START PRACTICINGPRACTICE
Frontend question · Testing › Async UI & act()

await screen.findByText('Saved') is equivalent to which of these?

await waitFor(() => screen.getByText('Saved'))

findBy* is getBy* retried inside waitFor until it succeeds or the timeout passes. So it equals await waitFor(() => screen.getByText('Saved')). The await screen.getByText option is tempting but does nothing extra, because getByText is synchronous. The fixed-sleep option is slow, and it is still flaky.