ByText
Finds nodes by the text they show, including a text input's value and placeholder.
screen.getByText(text: TextMatch, options?: MatchOptions): TestNode;
// also queryByText, getAllByText, queryAllByText, findByText, findAllByTextFinds nodes by the text they show: a Text's text (nested ones included),
and a text input's value or placeholder.
screen.getByText('0.50');
screen.getByText(/Test DAW · 96000 Hz/);
screen.getByText('Preset', { exact: false });Good to know
- For what is not a control: a value shown, a message. For a control,
ByRolewith its name says more: what it is, and that a screen reader finds it. - Whitespace is normalized and the whole text must match, unless
exact: false(part of it, ignoring case) or a regular expression. - Options as for every query.