testing-library / testing-library/user-event
selectOptions could use the aria-label to find the value too
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 258
- PR merge metrics
- No merged PRs in 30d
Description
Problem description
Hi,
I am using the library to test a component built with headlessUI's combobox and I am using the selectOptions method to select an option from the displayed listbox.
I have noticed that it's required that the value you provide matches exactly with the HTML value according to these lines of code . Would you accept a PR in which a check to the aria-label of the option is added?
Suggested solution
I was thinking about adding an additional check along the lines like:
var element = select.querySelector([aria-label=${option}]);
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/utility/selectOptions.ts at the linked option-matching logic. Check how selectOptions resolves the requested option and determine how aria-label matching should behave alongside the existing HTML value match. Done means the method can find the intended option by its aria-label without breaking existing selection behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend, testing
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100