Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hover then click children lost target #1187

Open
wsl874 opened this issue Jan 18, 2024 · 1 comment
Open

hover then click children lost target #1187

wsl874 opened this issue Jan 18, 2024 · 1 comment
Labels
bug Something isn't working needs assessment This needs to be looked at by a team member

Comments

@wsl874
Copy link

wsl874 commented Jan 18, 2024

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.

@wsl874 wsl874 added bug Something isn't working needs assessment This needs to be looked at by a team member labels Jan 18, 2024
@wsl874 wsl874 changed the title hover then click children failed test hover then click children lost target Jan 18, 2024
@tobiaseisenschenk
Copy link

tobiaseisenschenk commented Feb 7, 2024

I can confirm this issue. Regular clicks work, but combined with a hover action it does not. My setup is exactly that of the example above.

Environment

"@testing-library/react": "14.0.0"
"@testing-library/user-event": "^14.5.2"
"react": "18.2.0"
"react-dom": "18.2.0"

Workaround:

In case someone else is also blocked from writing their test - using testing-libraries fireEvent worked for me.

await user.hover(section)
// await user.click(btn)
fireEvent.click(btn)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs assessment This needs to be looked at by a team member
Projects
None yet
Development

No branches or pull requests

2 participants