-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Describe the bug
userEvent.hover and tooltip behavior
Hi! I ran into an issue while testing a component with a tooltip triggered on hover.
When using userEvent.hover(trigger), the tooltip never appears. After some investigation, it seems that although Playwright simulates hover events, there’s no initial pointer state, so the hover transition never actually occurs.
The only ways I’ve been able to make this work are:
Clicking document.body before hovering (to establish pointer state), or
Using Playwright’s page.mouse.move, which isn’t available when running tests in browser mode.
My questions:
Is this behavior expected for userEvent.hover?
Is clicking document.body an acceptable workaround, or is there a recommended pattern for hover-based UI like tooltips?
Can calling render method set the initial state so the click on document.body is not needed?
Thanks!
Reproduction
https://stackblitz.com/~/github.com/thaynarbo/hover-issue
System Info
System:
OS: macOS 15.3.1
CPU: (10) arm64 Apple M4
Memory: 78.09 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.19.0 - /Users/thaynar.lima/.nvm/versions/node/v20.19.0/bin/node
Yarn: 1.22.22 - /Users/thaynar.lima/.nvm/versions/node/v20.19.0/bin/yarn
npm: 11.7.0 - /Users/thaynar.lima/.nvm/versions/node/v20.19.0/bin/npm
Watchman: 2024.12.02.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 144.0.7559.110
Safari: 18.3
npmPackages:
@vitejs/plugin-react: ^5.1.1 => 5.1.2
@vitest/browser-playwright: ^4.0.18 => 4.0.18
playwright: ^1.58.1 => 1.58.1
vite: ^7.2.4 => 7.3.1
vitest: ^4.0.18 => 4.0.18
vitest-browser-react: ^2.0.5 => 2.0.5Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.