diff --git a/packages/enzyme-adapter-react-16.1/src/ReactSixteenOneAdapter.js b/packages/enzyme-adapter-react-16.1/src/ReactSixteenOneAdapter.js
index 40120d881..bb0b2eeaa 100644
--- a/packages/enzyme-adapter-react-16.1/src/ReactSixteenOneAdapter.js
+++ b/packages/enzyme-adapter-react-16.1/src/ReactSixteenOneAdapter.js
@@ -201,15 +201,22 @@ function nodeToHostNode(_node) {
while (node && !Array.isArray(node) && node.instance === null) {
node = node.rendered;
}
- if (Array.isArray(node)) {
- // TODO(lmr): throw warning regarding not being able to get a host node here
- throw new Error('Trying to get host node of an array');
- }
// if the SFC returned null effectively, there is no host node.
if (!node) {
return null;
}
- return ReactDOM.findDOMNode(node.instance);
+
+ const mapper = (item) => {
+ if (item && item.instance) return ReactDOM.findDOMNode(item.instance);
+ return null;
+ };
+ if (Array.isArray(node)) {
+ return node.map(mapper);
+ }
+ if (Array.isArray(node.rendered) && node.nodeType === 'class') {
+ return node.rendered.map(mapper);
+ }
+ return mapper(node);
}
const eventOptions = { animation: true };
diff --git a/packages/enzyme-adapter-react-16.2/src/ReactSixteenTwoAdapter.js b/packages/enzyme-adapter-react-16.2/src/ReactSixteenTwoAdapter.js
index 765edc49a..e52982bdf 100644
--- a/packages/enzyme-adapter-react-16.2/src/ReactSixteenTwoAdapter.js
+++ b/packages/enzyme-adapter-react-16.2/src/ReactSixteenTwoAdapter.js
@@ -202,15 +202,22 @@ function nodeToHostNode(_node) {
while (node && !Array.isArray(node) && node.instance === null) {
node = node.rendered;
}
- if (Array.isArray(node)) {
- // TODO(lmr): throw warning regarding not being able to get a host node here
- throw new Error('Trying to get host node of an array');
- }
// if the SFC returned null effectively, there is no host node.
if (!node) {
return null;
}
- return ReactDOM.findDOMNode(node.instance);
+
+ const mapper = (item) => {
+ if (item && item.instance) return ReactDOM.findDOMNode(item.instance);
+ return null;
+ };
+ if (Array.isArray(node)) {
+ return node.map(mapper);
+ }
+ if (Array.isArray(node.rendered) && node.nodeType === 'class') {
+ return node.rendered.map(mapper);
+ }
+ return mapper(node);
}
const eventOptions = { animation: true };
diff --git a/packages/enzyme-adapter-react-16.3/src/ReactSixteenThreeAdapter.js b/packages/enzyme-adapter-react-16.3/src/ReactSixteenThreeAdapter.js
index 76a538684..c14a04319 100644
--- a/packages/enzyme-adapter-react-16.3/src/ReactSixteenThreeAdapter.js
+++ b/packages/enzyme-adapter-react-16.3/src/ReactSixteenThreeAdapter.js
@@ -219,15 +219,22 @@ function nodeToHostNode(_node) {
while (node && !Array.isArray(node) && node.instance === null) {
node = node.rendered;
}
- if (Array.isArray(node)) {
- // TODO(lmr): throw warning regarding not being able to get a host node here
- throw new Error('Trying to get host node of an array');
- }
// if the SFC returned null effectively, there is no host node.
if (!node) {
return null;
}
- return ReactDOM.findDOMNode(node.instance);
+
+ const mapper = (item) => {
+ if (item && item.instance) return ReactDOM.findDOMNode(item.instance);
+ return null;
+ };
+ if (Array.isArray(node)) {
+ return node.map(mapper);
+ }
+ if (Array.isArray(node.rendered) && node.nodeType === 'class') {
+ return node.rendered.map(mapper);
+ }
+ return mapper(node);
}
const eventOptions = { animation: true };
diff --git a/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js b/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js
index abdedb309..e8e1937e2 100644
--- a/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js
+++ b/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js
@@ -219,15 +219,22 @@ function nodeToHostNode(_node) {
while (node && !Array.isArray(node) && node.instance === null) {
node = node.rendered;
}
- if (Array.isArray(node)) {
- // TODO(lmr): throw warning regarding not being able to get a host node here
- throw new Error('Trying to get host node of an array');
- }
// if the SFC returned null effectively, there is no host node.
if (!node) {
return null;
}
- return ReactDOM.findDOMNode(node.instance);
+
+ const mapper = (item) => {
+ if (item && item.instance) return ReactDOM.findDOMNode(item.instance);
+ return null;
+ };
+ if (Array.isArray(node)) {
+ return node.map(mapper);
+ }
+ if (Array.isArray(node.rendered) && node.nodeType === 'class') {
+ return node.rendered.map(mapper);
+ }
+ return mapper(node);
}
const eventOptions = {
diff --git a/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx b/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
index d11f1b805..0bbfbd84c 100644
--- a/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
+++ b/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
@@ -3702,6 +3702,38 @@ describeWithDOM('mount', () => {
expect(wrapper.text()).to.equal('{ some text }');
});
});
+
+ describeIf(is('> 16.2'), 'fragments', () => {
+ class FragmentClassExample extends React.Component {
+ render() {
+ return (
+