> For the complete documentation index, see [llms.txt](https://ploegert.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ploegert.gitbook.io/til/programmy/react-testing-library/find-by-queries-have-async-built-in.md).

# findBy\* Queries Have Async Built In

The `getBy*` queries provided by [DOM Testing Library](https://testing-library.com/docs/dom-testing-library/api-queries) allow you to find an element by various criteria in the rendered component. These queries are synchronous. If you need to find an element in response to an async event, you'll have to wrap it in a `waitFor` call.

DOM Testing Library also provides a set of `findBy*` queries as a convenience which have essentially wrapped the corresponding `getBy*` calls in `waitFor` calls under the hood.

You can use these with async/await:

```javascript
test("displays validation warnings for required fields", async () => {
  render(<MyFormComponent />);

  fireEvent.click(screen.getByText("Submit"));

  // validation on Name field
  const nameValidation = await screen.findByTestId("error-name");
  expect(nameValidation.innerHTML).toBe("Required");
});
```

[source](https://twitter.com/davidcrespo/status/1296639929376792577?s=20)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ploegert.gitbook.io/til/programmy/react-testing-library/find-by-queries-have-async-built-in.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
