Skip to content
masterclass Buddy

React Testing Library · Function

queryByRole

queryByRole finds one element by its ARIA role and optional filters such as accessible name. It returns null when there is no match, but throws when multiple elements match.

Last updated

Syntax

queryByRole(role, options?) -> HTMLElement | null

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • getByRole
  • getAllByRole
  • queryAllByRole
  • findByRole
  • findAllByRole
  • screen
  • within

Source: ByRole | Testing Library. Checked 2026-11-03.