How to find which properties are available for getByRole different elements?
Asked Answered
M

1

6

When writing unit tests with React Testing Library, we can access elements by their role with getByRole.

For example, if the element is heading, it has level option:

const headingNode = screen.getByRole('heading', { level: 3 });

Or if it's radio it has name:

 const radioNode = screen.getByRole('radio', { name: 'high'});

My question is, where can be found all the possible options for each type? Is there a documentation for this? Didn't find it.

Myocardiograph answered 4/1, 2023 at 15:49 Comment(0)
A
6

It is described in the documentation of the corresponding query:

Here you can see a table of HTML elements with their default and desired roles.

https://testing-library.com/docs/queries/byrole#api

Alleged answered 4/1, 2023 at 16:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.