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.
Read more
- About queries (https://testing-library.com/docs/queries/about)testing-library.com
- Async methods (https://testing-library.com/docs/dom-testing-library/api-async)testing-library.com