Skip to content

Commit 4333c2a

Browse files
Update api-queries.md
1 parent 9024115 commit 4333c2a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,22 @@ If it is important that you query an actual `<label>` element you can provide a
215215
<textarea></textarea>
216216
</label>
217217

218-
// for/htmlFor between label and an element that is not a form element
219-
<section id="photos-section">
220-
<label for="photos-section">Photos</label>
221-
</section>
222218
```
223219

224220
```js
225221
const inputNode = screen.getByLabelText('Username', { selector: 'input' })
226222
```
227223

224+
Note that `findByLabelText will not work in the case where a `for` attr on a `label` matches and `id` field on a non-form element.
225+
226+
```js
227+
// This case is not valid
228+
// for/htmlFor between label and an element that is not a form element
229+
<section id="photos-section">
230+
<label for="photos-section">Photos</label>
231+
</section>
232+
```
233+
228234
### `ByPlaceholderText`
229235

230236
> getByPlaceholderText, queryByPlaceholderText, getAllByPlaceholderText,

0 commit comments

Comments
 (0)