Accessibility · Junior · Question 65 of 75

Why does getByRole("button", { name: "Save" }) make tests better for a11y?

Show the answer

Correct answer: It fails if the element lacks that role or name

Explanation

The query looks at the accessibility tree, like assistive tech does. A div with a click handler won't be found, so the test exposes the bug.

Further reading

Problem with a question

Accessibility · Junior · question 65

Test yourself

Take the Accessibility · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz