Skip to content
masterclass Buddy

React Testing Library · Matcher

toBeInTheDocument

Use toBeInTheDocument to check that an element is in the document. Use its negated form with queryBy when checking that an element is absent.

Last updated

Syntax

expect(screen.queryByRole('button', { name: 'Submit' })).not.toBeInTheDocument()

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

Subscribe
  • queryBy
  • queryAllBy
  • getBy
  • toBeNull
  • @testing-library/jest-dom

Source: Appearance and Disappearance | Testing Library. Checked 2026-11-03.