Could not simulate mouseEnter event using React Test Utils

Currently mouseenter/mouseleave can't be simulated directly using ReactTestUtils; see this open issue: Simulate.mouseEnter and Simulate.mouseLeave not working.

As a workaround for now, you can use SimulateNative.mouseOver and SimulateNative.mouseOut (making sure to specify relatedTarget appropriately on each) and together they will cause React to fire onMouseEnter and onMouseLeave events.


This answer is a bit different now as the mouseOver event works in React since v0.11.1 - see here

That means you can now use

ReactTestUtils.Simulate.mouseEnter(events.refs.button.getDOMNode());

just as you tried in your example.

Tags:

Reactjs