Skip to content
masterclass Buddy

React Testing Library · Matcher

toHaveTextContent

toHaveTextContent checks that a selected React DOM element contains expected text. It is a custom matcher from @testing-library/jest-dom.

Last updated

Syntax

expect(element).toHaveTextContent(expectedText)

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

Subscribe
  • screen
  • getByRole
  • findByRole
  • @testing-library/jest-dom
  • toBeDisabled

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