Accessibility · Junior · Question 65 of 75
Why does getByRole("button", { name: "Save" }) make tests better for a11y?
- 1It speeds up tests by skipping the rendering step
- 2It fails if the element lacks that role or name
- 3It renders the component inside a real screen reader
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.