Skip to content

Commit

Permalink
[enzyme-adapter-react-{16,16.1,16.2,16.3}] [fix] simulateEvent: cal…
Browse files Browse the repository at this point in the history
…l the adapter’s implementation, not the raw one
  • Loading branch information
eps1lon authored and ljharb committed Apr 16, 2019
1 parent 0a17404 commit ee12c43
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class ReactSixteenOneAdapter extends EnzymeAdapter {
throw new TypeError(`ReactWrapper::simulate() event '${event}' does not exist`);
}
// eslint-disable-next-line react/no-find-dom-node
eventFn(nodeToHostNode(node), mock);
eventFn(adapter.nodeToHostNode(node), mock);
},
batchedUpdates(fn) {
return fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class ReactSixteenTwoAdapter extends EnzymeAdapter {
throw new TypeError(`ReactWrapper::simulate() event '${event}' does not exist`);
}
// eslint-disable-next-line react/no-find-dom-node
eventFn(nodeToHostNode(node), mock);
eventFn(adapter.nodeToHostNode(node), mock);
},
batchedUpdates(fn) {
return fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class ReactSixteenThreeAdapter extends EnzymeAdapter {
throw new TypeError(`ReactWrapper::simulate() event '${event}' does not exist`);
}
// eslint-disable-next-line react/no-find-dom-node
eventFn(nodeToHostNode(node), mock);
eventFn(adapter.nodeToHostNode(node), mock);
},
batchedUpdates(fn) {
return fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ class ReactSixteenAdapter extends EnzymeAdapter {
if (!eventFn) {
throw new TypeError(`ReactWrapper::simulate() event '${event}' does not exist`);
}
eventFn(nodeToHostNode(node), mock);
eventFn(adapter.nodeToHostNode(node), mock);
},
batchedUpdates(fn) {
return fn();
Expand Down
25 changes: 25 additions & 0 deletions packages/enzyme-test-suite/test/shared/methods/simulate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,5 +287,30 @@ export default function describeSimulate({
expect(onClick).to.have.property('callCount', 1);
});
});

describeIf(is('>= 16.6'), 'React.memo', () => {
itIf(isMount, 'can simulate events', () => {
function Child({ onClick }) {
return <button onClick={onClick} type="button" />;
}
const MemoizedChild = React.memo(Child);

function Parent(props) {
const { onClick } = props;

return <MemoizedChild onClick={onClick} />;
}

const handleClick = sinon.spy();
const wrapper = Wrap(<Parent onClick={handleClick} />);

wrapper.find(MemoizedChild).props().onClick();
expect(handleClick).to.have.property('callCount', 1);
wrapper.find(MemoizedChild).simulate('click');
expect(handleClick).to.have.property('callCount', 2);
wrapper.find(MemoizedChild).props().onClick();
expect(handleClick).to.have.property('callCount', 3);
});
});
});
}

0 comments on commit ee12c43

Please sign in to comment.