Asynchronous Element Queries with React Testing Library findBy

In the previous lessons, we worked with elements that were already present in the DOM when our tests ran.

Sometimes elements are expected to appear later (or disappear later). (Such as after API data is fetched or some timeout has run).

In these cases, you can use the findBy... queries. For example await screen.findByText('some button').

The findBy... functions are async functions, which will retry until finding the element or until it times out (by default after 2 seconds).

Loading full lesson content & code...

Ready to try running tests for this lesson?