testing-library / testing-library/user-event

.selectOptions triggering onChange on selected option

Open
#1,072 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
2.3k
Forks
258
PR merge metrics
No merged PRs in 30d

Description

Reproduction example

https://codesandbox.io/s/unruffled-http-tcih9v?file=/src/App.test.js

Prerequisites
  1. Run the test in the codesandbox link above.
Expected behavior

When using a native select element, as shown in the codesandbox browser, the onChange is only triggered when the option selected is NOT the currently selected option.

I expect the test to pass and the text "You have selected a new option" not to be in the document.

Actual behavior

The onChange is triggered when selecting the currently selected element and setting showMessage to true.

User-event version

14.1.1

Environment

please see codesandbox.

Additional context

No response

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 by running the reproduction test in the linked CodeSandbox and compare its behavior with a native select element. Trace the selectOptions entry point in this TypeScript project to determine why selecting the already-selected option triggers onChange. Done means the reproduction passes and no message appears when the current option is selected.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing
Issue type
Bug
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.