Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/__tests__/element-queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -830,3 +830,16 @@ test('can get a textarea with children', () => {
`)
getByLabelText('Label')
})

test('can get a select with options', () => {
const {getByLabelText} = renderIntoDocument(`
<label>
Label
<select>
<option>Some</option>
<option>Options</option>
</select>
</label>
`)
getByLabelText('Label')
})
6 changes: 6 additions & 0 deletions src/queries/label-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ function queryAllLabelsByText(
textToMatch = textToMatch.replace(textarea.value, '')
})

// The children of a select are also part of `textContent`, so we
// need also to remove their text.
Array.from(label.querySelectorAll('select')).forEach(select => {
textToMatch = textToMatch.replace(select.textContent, '')
})

return matcher(textToMatch, label, text, matchNormalizer)
})
}
Expand Down