Skip to content

Commit bf79b86

Browse files
committed
Update documentation for ByLabelText queries
Relates to [this PR](testing-library/dom-testing-library#373).
1 parent e845bd7 commit bf79b86

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

docs/dom-testing-library/api-queries.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,20 @@ cy.getByLabelText('username').should('exist')
131131

132132
<!--END_DOCUSAURUS_CODE_TABS-->
133133

134-
It will NOT find the input node for label text broken up by elements. For this
135-
case, you can provide a `selector` in the options:
134+
You may also need to filter down the results of the query.
135+
For that you can use the `selector` option:
136136

137-
```html
138-
<label> <span>Username</span> <input /> </label>
137+
```js
138+
// Label containing multiple elements
139+
<label>
140+
<span>Username</span>
141+
<input />
142+
</label>
143+
144+
// Multiple elements labelled via aria-labelledby
145+
<label id="username">Username</label>
146+
<input aria-labelledby="username" />
147+
<span aria-labelledby="username">Please enter your username</span>
139148
```
140149

141150
```js

0 commit comments

Comments
 (0)