react-popper-tooltip icon indicating copy to clipboard operation
react-popper-tooltip copied to clipboard

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

Open tomfridental1 opened this issue 3 years ago • 2 comments
trafficstars

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 avatar May 26 '22 10:05 tomfridental1

I can confirm that manipulating the mouse enter event works:

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

tomfridental1 avatar May 26 '22 12:05 tomfridental1

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

choucry13 avatar Oct 26 '22 19:10 choucry13