Skip to content

Commit

Permalink
Add a regression test for facebook#10906
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Oct 9, 2017
1 parent 4131af3 commit 5b64b65
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ var EnterLeaveEventPlugin;
var React;
var ReactDOM;
var ReactDOMComponentTree;
var ReactTestUtils;

describe('EnterLeaveEventPlugin', () => {
beforeEach(() => {
jest.resetModules();

React = require('react');
ReactDOM = require('react-dom');
ReactTestUtils = require('react-dom/test-utils');
// TODO: can we express this test with only public API?
ReactDOMComponentTree = require('ReactDOMComponentTree');
EnterLeaveEventPlugin = require('EnterLeaveEventPlugin');
Expand Down Expand Up @@ -58,4 +60,38 @@ describe('EnterLeaveEventPlugin', () => {
expect(enter.target).toBe(div);
expect(enter.relatedTarget).toBe(iframe.contentWindow);
});

// Regression test for https://github.com/facebook/react/issues/10906.
it('should find the common parent after updates', () => {
let parentEnterCalls = 0;
let childEnterCalls = 0;
let parent = null;
class Parent extends React.Component {
render() {
return (
<div
onMouseEnter={() => parentEnterCalls++}
ref={node => (parent = node)}>
{this.props.showChild &&
<div onMouseEnter={() => childEnterCalls++} />}
</div>
);
}
}

const div = document.createElement('div');
ReactDOM.render(<Parent />, div);
// The issue only reproduced on insertion during the first update.
ReactDOM.render(<Parent showChild={true} />, div);

// Enter from parent into the child.
ReactTestUtils.simulateNativeEventOnNode('topMouseOut', parent, {
target: parent,
relatedTarget: parent.firstChild,
});

// Entering a child should not fire on the child, not on the parent.
expect(childEnterCalls).toBe(1);
expect(parentEnterCalls).toBe(0);
});
});

0 comments on commit 5b64b65

Please sign in to comment.