vitest-dev / vitest-dev/vitest

`toHaveValue()` does not support `listbox` role for non-select elements

Open
#7,922 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feat: browser p2-nice-to-have
Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 22h
Merged PRs (30d)
94

Description

Clear and concise description of the problem

Currently, in browser mode, toHaveValue() does not work well with listbox role elements other than <select>

Image

The following two code snippets are semantically similar.

<ul role="listbox" aria-multiselectable="true">
  <li role="option" value="first">First Value</li>
  <li role="option" value="second" aria-selected="true">Second Value</li>
  <li role="option" value="third" aria-selected="true">Third Value</li>
</ul>
<select multiple>
  <option value="first">First Value</option>
  <option value="second" selected>Second Value</option>
  <option value="third" selected>Third Value</option>
</select>
Suggested solution

Supporting both would be helpful, as some UI component libraries generate the first one.

Alternative

No response

Additional context

Here is the reproducible CodeSandbox:

https://codesandbox.io/p/devbox/laughing-joliot-ssvs7n?file=%2Fsrc%2FListbox.test.tsx

After preparing this CodeSandbox, I noticed the stackblitz in the docs... If this is insufficient, please let me know and I will recreate it in stackblitz.

Validations

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

Run the linked CodeSandbox reproduction and read src/Listbox.test.tsx to understand the expected toHaveValue behavior. Trace the matcher entry point used by the browser-mode test, then verify that non-select listbox elements report their selected option values consistently with the provided select example.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing-qa
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.