Skip to content
masterclass Buddy

React Testing Library · Module

queryByAltText

queryByAltText finds one element by its alt attribute and returns null when no element matches. Use it when a missing element is an expected outcome.

Last updated

Syntax

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

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

Subscribe
  • getByAltText
  • getAllByAltText
  • queryAllByAltText
  • findByAltText
  • findAllByAltText
  • screen
  • within

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