testing-library / testing-library/dom-testing-library

getByRole should not find the element with user custom and invalid ARIA role.

Open
#1,192 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
3.3k
Forks
474
PR merge metrics
No merged PRs in 30d

Description

Relevant code or config:
<div role='item'>
  apple
</div>

// query
screen.getByRole('item')
What happened:

The testing playground query the element successfully and told me the div element has an "item" role.

Problem description:

But the "item" role is not a pre-defined ARIA role, so I expect that screen.getByRole('item') should not find the element.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the getByRole('item') query shown in the issue and inspect how @testing-library/dom validates ARIA roles. Compare the behavior with the predefined roles linked in the issue, then add or update a regression test for an element using the custom invalid role; done means the query no longer finds it.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
accessibility, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.