diff --git a/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js b/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js index ceab1f8ca..138b897c9 100644 --- a/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js +++ b/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js @@ -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. @@ -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 = { @@ -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(); @@ -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) {