Skip to content
masterclass Buddy

React Testing Library · Function

getByTestId

getByTestId finds an element by its test ID, usually the data-testid attribute. Use it after semantic queries such as role or text do not fit.

Last updated

Syntax

getByTestId(container: HTMLElement, text: TextMatch, options?: { exact?: boolean; normalizer?: NormalizerFn }): HTMLElement

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

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

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