Soundorv0.13.0

ByRole

Finds nodes by their accessibility role and name: the first query to reach for.

screen.getByRole(role: AccessibilityRole, options?: RoleOptions): TestNode;
// also queryByRole, getAllByRole, queryAllByRole, findByRole, findAllByRole

Finds nodes by their role (button, adjustable, textinput, dialog, …) and, usually, their accessible name: what a screen reader announces. A test that finds a control this way also checks that it is accessible.

screen.getByRole('button', { name: 'Reset gain' });
screen.getByRole('adjustable', { name: 'Gain', value: { now: 0.5 } });
screen.getByRole('switch', { name: 'Bypass', checked: true });

Options

OptionMatches
nameThe accessible name: a string, regular expression or function.
descriptionThe accessible description (the hint).
disabledDisabled, or not.
selectedSelected, or not.
checkedtrue, false or 'mixed'.
expandedExpanded, or not.
busyBusy, or not.
value{ min, max, now, text }: an adjustable's or a progress bar's value.
exact, hidden, normalizerAs for every query.

Good to know

  • Roles are Soundor's: a Pressable is a button unless given another role, a TextInput is a textinput, a Modal a dialog. See Accessibility for every role and default.
  • The name is the label (accessibilityLabel), else the text inside: a Pressable with <Text>Save</Text> is the button "Save".
  • Hidden nodes, and everything behind an open modal, are not found unless hidden: true: as a screen reader would not find them.

On this page