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

React testing library hover event not triggered when trigger text if wrapper with additional element #153

Open
tomfridental1 opened this issue May 26, 2022 · 2 comments

Comments

@tomfridental1
Copy link

tomfridental1 commented May 26, 2022

Describe the bug
While using the examples from this package test working fine, using <button ref={setTriggerRef}>text</button>
When testing the same code, but adding a span (or any other element) around the text (<button ref={setTriggerRef}><span>text</span></button>) the hover event isn't working. (logging the visible state stays false)

To Reproduce
Steps to reproduce the behavior:

  1. Use the same test setup from /test folder in this package
  2. wrap the trigger text with span tag.

Expected behavior
Expected hover inside nested child to work as well.

Desktop (please complete the following information):
Mac with VSCode and zsh terminal
@testing-library/react
@testing-library/user-event
Jest.

Additional context
This scenario still working on the app itself, the hover toggles the "visible" status to true.
If you change the trigger to click, the test is working.

I'm assume it's something to do with onMouseEnter isn't bubbling.

Thanks!

@tomfridental1
Copy link
Author

tomfridental1 commented May 26, 2022

I can confirm that manipulating the mouse enter event works:

fireEvent(element, new MouseEvent('mouseenter', { bubbles: true }));
  await waitFor(() => screen.getByText(overlayText));

@choucry13
Copy link

Hi @tomfridental1 , any update with a possibility to use useEvent.hover from @testing-library/user-event ?
(and thank again for your answer with fireEvent ^^)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants