Commit 6ef63b7
authored
fix: null labels on hidden inputs (#804)
* Ensure hidden inputs are not labelable
The `labels` property on `input` elements of type `hidden` is `null`
rather than `NodeList` [1]. This meant the `getRealLabels` function
would return `null` causing `queryAllByLabelText` to throw an error when
it tried to call `length` on `null` [2].
This commit fixes the issue by ensuring the element is labelable before
calling `labels` on it, and adds a test case for this specific scenario.
[1]: https://html.spec.whatwg.org/multipage/forms.html#dom-lfe-labels
[2]: https://github.com/testing-library/dom-testing-library/blob/62f4e5e09a4b81ef66679560b540523edccdef98/src/queries/label-text.js#L52
* squash! Ensure hidden inputs are not labelable
This commit fixes the issue by retuning an empty array if the `labels`
property is `null`, and adds a test case for this specific scenario.1 parent 62f4e5e commit 6ef63b7
File tree
3 files changed
+9
-1
lines changed- src
- __tests__
3 files changed
+9
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
0 commit comments