-
Notifications
You must be signed in to change notification settings - Fork 472
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
[v7] *ByLabelText finding additional elements when descendants of label #482
Comments
I don't know But |
I think the behavior is correct. If you have an element inside a label then technically the label is labeling that element. The fix would be: test('getByLabelText and label descendents', () => {
render(
<>
<label htmlFor="text-input">
<h2>Enter your text here:</h2>
<div>
<input id="text-input" name="text" type="text" />
</div>
</label>
<button type="submit">Submit</button>
</>,
);
screen.getByLabelText(/your text here/i);
}); Or you could use the new |
In any case, I don't think this is a bug, so I'll go ahead and close this one. Let me know if I misunderstood the situation. |
Huh, apparently multiple descendants are allowed but, only certain phrasing content elements which are not labelable ( Axe has never complained about this structure, but I suppose it's not so much an a11y issue as it is a structural/validity issue. Anyway, easy enough to fix. Thanks, and sorry for the noise. Reference: |
Thanks for doing that research @wKovacs64! 👏 |
dom-testing-library
version: 7.0.3node
version: 12.16.1npm
(oryarn
) version: yarn v1.22.0Relevant code or config:
What you did:
I upgraded @testing-library/react from v.9.50 to v10.0.1 (and thus, @testing-library/dom from v6 to v7).
What happened:
A particular class of tests started to fail with the following message:
Reproduction repository:
https://codesandbox.io/s/dom-testing-library-v7-label-descendants-issue-cw8mb?module=%2Fsrc%2F__tests__%2Findex.test.js&previewwindow=tests
Problem description:
The
*ByLabelText
queries used to find just theinput
but now they find theinput
and thebutton
when nested under alabel
. I'm not using theselector
option, but I think this might have been introduced in #373.Suggested solution:
Not sure yet, ran out of time. It's quite possible I'm just doin' it wrong™️ , too.
The text was updated successfully, but these errors were encountered: