-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fireEvent - mouseEnter/mouseLeave not working with addEventListener #577
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 - mouseEnter/mouseLeave not working with addEventListener #577
Comments
Looking under the hood at the logic here and mouseEnter definition here, I didn't see anything that specifically looked problematic. I recreated the logic as best I could in the browser, and it seemed fine:
|
Upon further testing, I noticed by creating the event myself and passing it to const mouseenter = new MouseEvent("mouseenter", {
bubbles: false,
cancelable: false
});
fireEvent(getByText("no"), mouseenter);
// Passes! |
Ok, found the issue. These lines re-assign Hmm... I have a fuzzy understanding that React is doing some non-standard thing with these events under the hood, and that this is a workaround. What are our options here? |
Hi @greypants, Thanks for the issue. Yeah, sorry about that. I can't remember exactly the reasons for the non-standard event stuff in React, but that's what we needed to do to get things working with react event props. I'm not sure what to do here, and I'm afraid I don't have the bandwidth right now to look into it 😬 Sorry. Anyone else have ideas/want to dig? |
Looks like an interesting problem. I can have a look at it over the weekend or next week. I won't have time for it this Thursday or Friday. If anyone else wants to pick it up feel free. |
So there are the four cases we want to work with the fireEvent utility.
Currently, number 1 does not work. We want to make a change to fix 1, without breaking the others. Here's a test people we can use to ensure we have done that. So as long as the following tests pass, I'm assuming there shouldn't be any issues getting this change in. (Like others, I unfortunately don't have time to look into this right now, but maybe in a couple months)
|
🎉 This issue has been resolved in version 9.4.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Not sure the case is relevant to the topic. But for people who look an information about fireEvent.mouseEnter by search phrase like In my case fireEvent.mouseEnter worked only if before I did fireEvent.mouseOver <Cell
onMouseEnter={() => { console.log("FIRE! ".repeat(50))}}
data-testid='test-item'
/> const testItem = () => document.querySelector('[data-testid="test-item"]')
render(<Table />)
act(() => {
fireEvent.mouseOver(testItem())
fireEvent.mouseEnter(testItem())
}) output
|
@the-teacher had same issue, thank you! |
react-testing-library
version: 9.4.0react
version: 16.12.0node
version: 10.16.0npm
(oryarn
) version: 1.21.1Relevant code or config:
What you did:
I'm using a third party library that attaches
mouseenter
andmouseleave
events to a DOM element accessed via a Reactref
viaHTMLElement.addEventListener
. Was testing this behavior.What happened:
Works fine in the browser, but when writing my tests, I noticed that
fireEvent.mouseEnter
andfireEvent.mouseLeave
have no effect. What's weird is if I leave the test alone, but change the event in the component tomouseover/mouseout
, it works. If I attach the events the react way, viaonMouseEnter
andonMouseLeave
, it also works.Reproduction:
https://codesandbox.io/s/react-testing-library-demo-37yqv?fontsize=14&hidenavigation=1&theme=dark
Problem description:
fireEvent.mouseLeave
andfireEvent.mouseOver
do not work when the events are added viaaddEventListener
.Suggested solution:
It may have something to do with this: https://reactjs.org/docs/events.html#mouse-events
If this is a React limitation, or if there's a workaround, it would be great to add it to the FAQ.
The text was updated successfully, but these errors were encountered: