testing-library / testing-library/user-event
`selectOptions` selects by `innerHTML` not `innerText`
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 258
- PR merge metrics
- No merged PRs in 30d
Description
Reproduction example
https://codesandbox.io/s/testing-library-selectoptions-innertext-iw1bbk?file=/src/App.test.js
Prerequisites
- Render a
role="listbox" select withrole="option"` items where each option contains aria-hidden decorative icon. - Call
selectOptionsjust with the option text, not entire inner HTML.
Expected behavior
The option with innerText equal to the argument passed to selectOptions gets selected.
Actual behavior
The test fails with "Value ${optionText} not found in options".
User-event version
^14.4.3
Environment
Testing Library framework: @testing-library/react@14.0.0
JS framework: react@18.2.0
Test environment: jest@27.5.1 and @storybook/jest@0.1.0
DOM implementation: jsdom@16.7.0
Additional context
The relevant code in user-event is here: https://github.com/testing-library/user-event/blob/7a305dee9ab833d6f338d567fc2e862b4838b76a/src/utility/selectOptions.ts#L45-L49
I propose adding || o.innerText === val.
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 selection logic, then run the linked CodeSandbox reproduction with an aria-hidden decorative icon inside an option. Done means selecting by the visible option text succeeds while existing option selection behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react, typescript
- Domain
- frontend, testing-qa
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100