-
Notifications
You must be signed in to change notification settings - Fork 470
Inconsistent behavior of selector
option
#372
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
Yup, I've encountered this myself and it was annoying. Honestly, I think this is a bug and the intended behavior has always been what you're suggesting. Could you open a pull request with a fix please? |
🎉 This issue has been resolved in version 6.16.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Closes #372 BREAKING CHANGE: If you used the `selector` option in `ByLabelText` queries, then you will probably need to update that code to be able to find the label you're looking for.
Closes #372 BREAKING CHANGE: If you used the `selector` option in `ByLabelText` queries, then you will probably need to update that code to be able to find the label you're looking for.
🎉 This issue has been resolved in version 7.0.0-beta.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Closes #372 BREAKING CHANGE: If you used the `selector` option in `ByLabelText` queries, then you will probably need to update that code to be able to find the label you're looking for.
Closes #372 BREAKING CHANGE: If you used the `selector` option in `ByLabelText` queries, then you will probably need to update that code to be able to find the label you're looking for.
🎉 This issue has been resolved in version 7.0.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
DOM Testing Library
version: 6.3.0node
version: 8.12.0 (& whatever codesandbox is on)npm
(oryarn
) version: 6.4.1 (& whatever codesandbox is on)Relevant code or config:
I have two main examples:
The documentation here suggests that the second one should not work and that the
selector
option is necessary.What you did:
I was trying to test an interaction with a dropdown I made using Downshift. My hope was that I could select the input element using
getByLabelText
but that does not appear to be the case. In Downshift, multiple elements (e.g. the input element, the option list itself, the root div) get associated with the label viaaria-labelledby
. When I tried to filter the options down using theselector
option, that lead me down this rabbit hole.What happened:
It did not work the way I had hoped (filtering the results down based on the selector I provided). However, it also doesn't appear to work the way the documentation says it's supposed to work. The documentation I linked about provides this example:
And says this:
So it appears that the
selector
option for thegetByLabelText
is intended for filtering out elements that are inside labels. But as can be seen the codesandbox below, it is not actually necessary in the example given.Reproduction:
https://codesandbox.io/embed/react-testing-library-demo-jipd1
Problem description:
It seems like the purpose and behavior of the
selector
option is inconsistent. In the reproduction above, you can see that it works with thegetByText
query the way I, personally, would expect it to. If two elements have the same text but only one matches the provided selector, that one gets returned. ForgetByLabelText
though, it does not work that way. If I have multiple elements that point to the same label viaaria-labelledby
and I do agetByLabelText
, providing aselector
doesn't do anything and it throws an error unless I usegetAllByLabelText
.Suggested solution:
I think it would make sense for it to behave more like the way it does for
getByText
. So it would:If you agree, I would be happy to take a stab at this and put up a PR.
The text was updated successfully, but these errors were encountered: