Closed
Description
dom-testing-library
version: 7.0.3node
version: 12.16.1npm
(oryarn
) version: yarn v1.22.0
Relevant code or config:
test('getByLabelText and label descendants', () => {
render(
<label htmlFor="text-input">
<h2>Enter your text here:</h2>
<div>
{/* should just find this input */}
<input id="text-input" name="text" type="text" />
{/* but v7 also finds this button */}
<button type="submit">Submit</button>
</div>
</label>,
);
screen.getByLabelText(/your text here/i);
});
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:
TestingLibraryElementError: Found multiple elements with the text of: /your text here/
(If this is intentional, then use the `*AllBy*` variant of the query (like `queryAllByText`, `getAllByText`, or `findAllByText`)).
Reproduction repository:
Problem description:
The *ByLabelText
queries used to find just the input
but now they find the input
and the button
when nested under a label
. I'm not using the selector
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.
Metadata
Metadata
Assignees
Labels
No labels