-
Notifications
You must be signed in to change notification settings - Fork 471
*ByLabelText can't find password inputs #737
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
Hi @DanielGibbsNZ, Read up on this limitation here: #567 password fields are absolutely accessible via |
@kentcdodds Sorry about that. I thought I searched the issues for "password" but I may have been searching the wrong repo (probably I've tried using
This seems odd given that the linked document explicity says that a (non-hidden) |
This is a bug. I'll retitle and reopen this issue. If you'd like to dive in and fix this then here's the file you'll be working in: https://github.com/testing-library/dom-testing-library/blob/master/src/queries/label-text.js And here's where you could add a test for this case: https://github.com/testing-library/dom-testing-library/blob/master/src/__tests__/element-queries.js Let me know. If you don't have time or don't want to, I can fix this one later today. |
It looks like to me Sorry if I am missing something. I just jumped in this issue and I would have liked to help so I tried to add a test in our code base and it works, then I checked the codesandbox and it looks like working as well (with |
Thanks @delca85, I'm guessing the issue is the version of JSDOM being used. I'd suggest upgrading to the latest version. Considering that, there's nothing more we can do here. |
Yep that seems to be it, upgrading |
No worries @DanielGibbsNZ :) |
I came across this issue while fruitlessly googling |
For others who may be reading this, don't discount what @modernserf says even if you're sure you aren't rendering multiple elements with the same ID! I had this issue too and it turned out to be that this issue with the React testing library was leading to there being a ghost DOM that contained the element in question in addition to the one I had rendered for that test. Unfortunately, it seems there's not a good solution to the ghost DOM issue yet, but I've mitigated it by separating offending tests into their own files. A bit annoying but it got the tests working. |
Environment
@testing-library/dom
version: 7.22.1jest
version: 22.4.4jest-environment-jsdom
version: 22.4.3yarn
version: 1.22.4node
version: 10.15.3Relevant code or config:
What you did:
I tried to get a password input using
getByRole("textbox")
. I've also triedgetByLabelText("Password")
.What happened:
No element is found, and an error message such as
Unable to find an element with the role "textbox"
is shown.Reproduction:
https://codesandbox.io/s/react-testing-library-getbyrole-password-issue-roy0l
Problem description:
It makes it difficult to test a login form without falling back to query selectors or test IDs, something that the library guidelines say should only be used if there is no other choice.
Suggested solution:
Either allow password fields to be found using
getByRole("textbox")
or support another role if appropriate.Supporting password fields in
getByLabelText
would also solve the problem for me.The text was updated successfully, but these errors were encountered: