-
Notifications
You must be signed in to change notification settings - Fork 468
Closed
Description
DOM Testing Library
version: 6.0.0node
version: v12.3.1npm
(oryarn
) version: yarn@1.17.3
Relevant code or config:
const {getByLabelText} = render(
<label>
Label
<textarea defaultValue="value" />
</label>
);
getByLabelText('Label');
What you did:
Run the test.
What happened:
Unable to find a label with the text of: Label
<body>
<div>
<label>
Label
<textarea>
value
</textarea>
</label>
</div>
</body>
113 | </label>
114 | );
> 115 | getByLabelText('Label');
| ^
116 | });
117 |
at getElementError (node_modules/@testing-library/dom/dist/query-helpers.js:22:10)
at getAllByLabelText (node_modules/@testing-library/dom/dist/queries/label-text.js:104:43)
at node_modules/@testing-library/dom/dist/query-helpers.js:59:17
at Object.getByLabelText (src/components/Test/__tests__/Test-test.js:115:3)
Interestingly it works once you remove defaultValue="value"
Reproduction:
https://codesandbox.io/s/react-testing-library-demo-olewk
Problem description:
According to the docs this should work:
<label>Username <input /></label>
Suggested solution:
I guess the bug is somewhere here: https://github.com/testing-library/dom-testing-library/blob/master/src/queries/label-text.js
Metadata
Metadata
Assignees
Labels
No labels