Skip to content

Commit

Permalink
[enzyme-react-adapter-{16,16.1,16.2,16.3}] [fix] nodeToHostNode req…
Browse files Browse the repository at this point in the history
…uire `supportsArray` argument to return an array.

[enzyme] [patch] `mount`: provide `supportsArray` to `adapter.nodeToHostNode`

Fixes enzymejs#2002.
  • Loading branch information
ljharb committed Feb 5, 2019
1 parent 8d245ba commit 8221765
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,12 @@ class ReactSixteenOneAdapter extends EnzymeAdapter {
return elementToTree(element);
}

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

displayNameOfNode(node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,12 @@ class ReactSixteenTwoAdapter extends EnzymeAdapter {
return elementToTree(element);
}

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

displayNameOfNode(node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,12 @@ class ReactSixteenThreeAdapter extends EnzymeAdapter {
return elementToTree(element);
}

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

displayNameOfNode(node) {
Expand Down
8 changes: 6 additions & 2 deletions packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,12 @@ class ReactSixteenAdapter extends EnzymeAdapter {
return elementToTree(element);
}

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

displayNameOfNode(node) {
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5168,7 +5168,7 @@ describeWithDOM('mount', () => {
});
});

describeIf(is('>16.2'), 'fragments', () => {
describeIf(is('>16.2'), 'Fragments', () => {
class FragmentClassExample extends React.Component {
render() {
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5240,7 +5240,7 @@ describe('shallow', () => {
});
});

describeIf(is('>16.2'), 'fragments', () => {
describeIf(is('>16.2'), 'Fragments', () => {
class FragmentClassExample extends React.Component {
render() {
return (
Expand Down
4 changes: 2 additions & 2 deletions packages/enzyme/src/ReactWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class ReactWrapper {
*/
getDOMNode() {
const adapter = getAdapter(this[OPTIONS]);
return this.single('getDOMNode', n => adapter.nodeToHostNode(n));
return this.single('getDOMNode', n => adapter.nodeToHostNode(n, true));
}

/**
Expand Down Expand Up @@ -575,7 +575,7 @@ class ReactWrapper {
text() {
const adapter = getAdapter(this[OPTIONS]);
return this.single('text', (n) => {
const node = adapter.nodeToHostNode(n);
const node = adapter.nodeToHostNode(n, true);
if (!node) {
return typeof n === 'string' ? n : node;
}
Expand Down

0 comments on commit 8221765

Please sign in to comment.