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"
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
This seems to be happening to any component I add a custom role to, and was working in previous versions.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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: