testing-library / testing-library/user-event

hover then click children lost target

Open
#1,187 4 comments 6 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/p/devbox/react-jest-test-4yx2wr?file=/src/App.js

Prerequisites
  1. An element contains a child element, and the child element is only displayed when mouse hover
  2. test hover the element, then click child element
Expected behavior

child element displayed and click event is triggered

Actual behavior

child element hidden, and click event is not triggered

User-event version

14.5.2

Environment

Testing Library framework: @testing-library/react@14.1.2

JS framework: react@18.0.2

Test environment:

DOM implementation:

Additional context

I debugged the code and found that the pointer event compared prevTarget and currTarget. When they are not equal, the mouseLeave event will be triggered, which will cause the child elements to be hidden and the target to be lost in subsequent events.
Maybe we can determine whether to trigger the mouseLeave event based on the node level, which will be closer to the browser's implementation.

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 the linked CodeSandbox reproduction and trace the pointer-event handling that compares the previous and current targets. Check the existing interaction tests around hover and click behavior, then verify that hovering reveals the child and clicking it triggers the event without hiding the child first.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.