Skip to content
masterclass Buddy

React Testing Library · Module

queryByTestId

ByTestId queries find elements by their data-testid attribute. Use them after user-focused queries do not fit, and prefer them over DOM-structure or CSS-class selectors.

Last updated

Syntax

getByTestId(container, text, options?) : HTMLElement

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

Subscribe
  • getByTestId
  • queryByTestId
  • getAllByTestId
  • queryAllByTestId
  • findByTestId
  • findAllByTestId
  • configure
  • screen

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