-
Notifications
You must be signed in to change notification settings - Fork 470
Unable to find an accessible element with the role "form" #474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is actually intended by spec. A Though we could extend the error message to add a hint if a role is queried where an element needs an accessible name to have that role. |
So it's changed from Thanks for your help! |
In my case, neither |
…omponent This change is also needed by #1484: - the "role" attribute makes the alert "searchable" by screen.getByRole() - the "aria-label" attribute makes the form "searchable" by screen.getByRole() (testing-library/dom-testing-library#474 (comment)) Part of #1493
If I have: <form name="profile" action="#" >
</form> It works when querying with |
|
@alexkrolick When you run <form action="#"></form>
|
I see aria-query (which powers getByRole) implements that but I am not sure that is correct behavior. At least in Chrome devtools, a form with just a name attribute doesn't have an accessible name. |
As @alexkrolick mentioned, the |
Alright, thank you @MatanBobi and @alexkrolick for your explanation. 👍 |
I disagree on this. This can lead to fragile tests. |
While I agree with you @andremarcondesteixeira, if this is per the spec I'm not sure it's good diverting from it. |
I get what you're saying but the same can happen if the engineer removes the |
Solved for me by enabling the
|
DOM Testing Library
version: 9.5.0 (react library)node
version: Whatever CodeSandbox runs on for React sandboxesnpm
(oryarn
) version: Whatever CodeSandbox runs on for React sandboxesRelevant code or config:
What you did:
Trying to select the form element by role. This also fails with
findByRole
.What happened:
Adding
role='form'
to form element does find the form element but should not be required.Reproduction:
https://codesandbox.io/s/falling-surf-0br51
Looks like bug was introduced in 16.4.1 as 16.4.0 works fine (with 9.4.1 version of @testing-library/react):
https://codesandbox.io/s/dom-testing-library-template-kzorw
Problem description:
Fails tests that are asserting that an accessible form is in the DOM.
Suggested solution:
aria-query looks to still be exporting
form
in the roles map so that's probably not the issue. Other than that not had enough time to dig further.The text was updated successfully, but these errors were encountered: