Skip to content
masterclass Buddy

React Testing Library · Function

within

within scopes Testing Library queries to one container instead of the whole document. In the TestCafe integration, the container can be a query result, CSS selector string, or TestCafe selector.

Last updated

Syntax

within(container).getByText('hello')

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

Subscribe
  • getByText
  • getByTestId
  • getAllByTestId
  • screen

Source: Querying Within Elements | Testing Library. Checked 2026-11-03.