Skip to content
masterclass Buddy

React Testing Library · Module

getByAltText

getByAltText finds an element by its alt text. It is commonly used for images and can also support other elements that accept alt.

Last updated

Syntax

getByAltText(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
  • queryByAltText
  • getAllByAltText
  • queryAllByAltText
  • findByAltText
  • findAllByAltText
  • screen
  • within
  • TextMatch

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