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

fireEvent used with pointerEnter and pointerLeave don't fire in React #783

Closed
itaylor opened this issue Sep 12, 2020 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@itaylor
Copy link

itaylor commented Sep 12, 2020

  • @testing-library/react version: 11.0.2
  • Testing Framework and version: Jest 26.4.2
  • DOM Environment: jsdom

Relevant code or config:

https://codesandbox.io/s/react-testing-library-demo-forked-fkjt7?file=/src/__tests__/HoverTest.test.js
https://codesandbox.io/s/react-testing-library-demo-forked-fkjt7?file=/src/HoverTest.js

What you did:

I am trying to test PointerEvents that had been converted from MouseEvents. The pointerEnter pointerLeave don't work the same as the mouseEnter mouseLeave in testing library, but works fine in the browser.

What happened:

When I use fireEvent.pointerEnter in my test, my React component's onPonterEnter handler is not hit.

Reproduction:

https://codesandbox.io/s/react-testing-library-demo-forked-fkjt7?file=/src/__tests__/HoverTest.test.js

Problem description:

It's highly confusing that firing pointerEnter doesn't cause react onPointerEnter to fire.

Suggested solution:

In #588 mouseEnter/mouseLeave had special handlers added to deal with the fact that React doesn't attach the native event and instead uses mouseOver / mouseOut. I think the same fix should be made for pointerEnter / pointerLeave

You wan work around this by firing pointerOver / pointerOut, but this is not ideal, as it requires the user to understand React's event model.

@eps1lon
Copy link
Member

eps1lon commented Sep 12, 2020

In #588 mouseEnter/mouseLeave had special handlers added to deal with the fact that React doesn't attach the native event and instead uses mouseOver / mouseOut. I think the same fix should be made for pointerEnter / pointerLeave

Tested it quickly with firing pointerOver instead of pointerEnter and it does indeed seem to fix it.

A pull request would be much appreciated. Adding tests similar to the ones in #588 would be a good starting points. If you can't get the fix to work then feel free to open a PR with the test only. That would already help us a lot.

@eps1lon eps1lon added the bug Something isn't working label Sep 12, 2020
@karthick3018
Copy link
Contributor

karthick3018 commented Sep 12, 2020

@eps1lon i've raised a PR https://github.com/testing-library/react-testing-library/pull/784 kindly check if that is ok

@eps1lon
Copy link
Member

eps1lon commented Sep 13, 2020

Closed in #784. We also uncovered another bug related got gotpointercapture and lostpointercaputre which got fixed with #786. @testing-library/react@^11.0.4 should have considerably better support for testing event handlers.

@eps1lon eps1lon closed this as completed Sep 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants