question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to find role

See original GitHub issue
  • @testing-library/react version: 11.2.0
  • Testing Framework and version: Jest (CRA) 26.6.0
  • DOM Environment: jsdom

Problem description:

Unable to find role="execute-button000"

image

It says it can’t find that role, but as you can see in the debug print, it clearly exists in the DOM. This also fails for screen.findByRole

image

This seems to be happening to any component I add a custom role to, and was working in previous versions.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
gabrielliwerantcommented, Oct 14, 2021

This fails for valid roles as well. It’s overeager in ignoring roles. For example, when creating “listbox” roles out of lists for selects that don’t use the native element, as is standard in many UI libraries like material-ui. Frankly, the opinionated nature of testing-library is highly frustrating because it edges out all kinds of valid, common use cases. I’d like to decide as the dev and designer when a role is valid or not, not a library.

These decisions are basically forcing me into data-testids.

4reactions
brendan-donegancommented, Nov 19, 2020

But your button should have an aria-label for screen readers so why not just add one, like ‘Execute’ for example? Then you could do getByRole('button', { name: 'Execute' });

On Thu, 19 Nov 2020 at 17:46, ngoble-phdata notifications@github.com wrote:

Yeah I understand now from your previous comment that it’s not a valid accessibility role. I’m having a hard time targeting this because it’s a button with an SVG as the content, so I can’t use text within the button to target it.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/testing-library/react-testing-library/issues/835#issuecomment-730534909, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASLMLWEGX6PPFITICY6K6TSQVKZFANCNFSM4T3WB73A .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cant find button using Test Library (React) - Stack Overflow
Unable to find role="button". I just lost half an hour on a simple typo and a bad error message.. Share. Share a link...
Read more >
Making sure you're using the correct query - Tim Deschryver
. Check the list of roles. The short answer to "which query should I use", is most of the time the *ByRole query....
Read more >
ByRole | Testing Library
It can be used to query a specific element if multiple elements with the same role are present on the rendered content. For...
Read more >
Unable to run Packer to create Image - Unable to find role
Hi Team,. We are unable to create image using packer. Can someone explain why the code fails even though ROLE:“ansible-role-vault”
Read more >
Troubleshoot unavailable IAM roles when launching instances
I created a new AWS Identity and Access Management (IAM) role, but I can't find the role in the dropdown list when launching...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found