testing-library / testing-library/user-event

`selectOptions` selects by `innerHTML` not `innerText`

Open
#1,127 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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
  1. Render a role="listbox" select with role="option"` items where each option contains aria-hidden decorative icon.
  2. Call selectOptions just 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.