Skip to content

Commit

Permalink
Use arrow function to get actual this
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Apr 16, 2019
1 parent 9ef0776 commit f13cc40
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function childrenToTree(node) {
return flatten(children.map(toTree));
}

function nodeToHostNode(_node, supportsArray = false) {
function nodeToHostNode(_node) {
// NOTE(lmr): node could be a function component
// which wont have an instance prop, but we can get the
// host node associated with its return value at that point.
Expand All @@ -266,20 +266,13 @@ function nodeToHostNode(_node, supportsArray = false) {
if (item && item.instance) return ReactDOM.findDOMNode(item.instance);
return null;
};

let nodes;
if (Array.isArray(node)) {
nodes = node.map(mapper);
} else if (Array.isArray(node.rendered) && node.nodeType === 'class') {
nodes = node.rendered.map(mapper);
} else {
nodes = mapper(node);
return node.map(mapper);
}

if (Array.isArray(nodes) && !supportsArray) {
return nodes[0];
if (Array.isArray(node.rendered) && node.nodeType === 'class') {
return node.rendered.map(mapper);
}
return nodes;
return mapper(node);
}

const eventOptions = {
Expand Down Expand Up @@ -428,13 +421,13 @@ class ReactSixteenAdapter extends EnzymeAdapter {
is166 ? catchingType : undefined,
);
},
simulateEvent(node, event, mock) {
simulateEvent: (node, event, mock) => {
const mappedEvent = mapNativeEventNames(event, eventOptions);
const eventFn = TestUtils.Simulate[mappedEvent];
if (!eventFn) {
throw new TypeError(`ReactWrapper::simulate() event '${event}' does not exist`);
}
eventFn(nodeToHostNode(node), mock);
eventFn(this.nodeToHostNode(node), mock);
},
batchedUpdates(fn) {
return fn();
Expand Down Expand Up @@ -662,7 +655,11 @@ class ReactSixteenAdapter extends EnzymeAdapter {
}

nodeToHostNode(node, supportsArray = false) {
return nodeToHostNode(node, supportsArray);
const nodes = nodeToHostNode(node);
if (Array.isArray(nodes) && !supportsArray) {
return nodes[0];
}
return nodes;
}

displayNameOfNode(node) {
Expand Down

0 comments on commit f13cc40

Please sign in to comment.