Skip to content

Commit

Permalink
add portal support
Browse files Browse the repository at this point in the history
  • Loading branch information
jgzuke committed Aug 16, 2018
1 parent 984a4fb commit c74acb4
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 13 deletions.
13 changes: 10 additions & 3 deletions packages/enzyme-adapter-react-16.1/src/ReactSixteenOneAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,16 @@ function toTree(vnode) {
switch (node.tag) {
case HostRoot: // 3
return childrenToTree(node.child);
case HostPortal: { // 4
return childrenToTree(node.child);
}
case HostPortal: // 4
return {
nodeType: 'portal',
type: Portal,
props: {},
key: ensureKeyOrUndefined(node.key),
ref: node.ref,
instance: null,
rendered: childrenToTree(node.child),
};
case ClassComponent:
return {
nodeType: 'class',
Expand Down
13 changes: 10 additions & 3 deletions packages/enzyme-adapter-react-16.2/src/ReactSixteenTwoAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,16 @@ function toTree(vnode) {
switch (node.tag) {
case HostRoot: // 3
return childrenToTree(node.child);
case HostPortal: { // 4
return childrenToTree(node.child);
}
case HostPortal: // 4
return {
nodeType: 'portal',
type: Portal,
props: {},
key: ensureKeyOrUndefined(node.key),
ref: node.ref,
instance: null,
rendered: childrenToTree(node.child),
};
case ClassComponent:
return {
nodeType: 'class',
Expand Down
13 changes: 10 additions & 3 deletions packages/enzyme-adapter-react-16.3/src/ReactSixteenThreeAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,16 @@ function toTree(vnode) {
switch (node.tag) {
case HostRoot: // 3
return childrenToTree(node.child);
case HostPortal: { // 4
return childrenToTree(node.child);
}
case HostPortal: // 4
return {
nodeType: 'portal',
type: Portal,
props: {},
key: ensureKeyOrUndefined(node.key),
ref: node.ref,
instance: null,
rendered: childrenToTree(node.child),
};
case ClassComponent:
return {
nodeType: 'class',
Expand Down
13 changes: 10 additions & 3 deletions packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,16 @@ function toTree(vnode) {
switch (node.tag) {
case HostRoot: // 3
return childrenToTree(node.child);
case HostPortal: { // 4
return childrenToTree(node.child);
}
case HostPortal: // 4
return {
nodeType: 'portal',
type: Portal,
props: {},
key: ensureKeyOrUndefined(node.key),
ref: node.ref,
instance: null,
rendered: childrenToTree(node.child),
};
case ClassComponent:
return {
nodeType: 'class',
Expand Down
3 changes: 2 additions & 1 deletion packages/enzyme-adapter-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"dependencies": {
"function.prototype.name": "^1.1.0",
"object.assign": "^4.1.0",
"prop-types": "^15.6.2"
"prop-types": "^15.6.2",
"react-is": "^16.4.2"
},
"peerDependencies": {
"react": "0.13.x || 0.14.x || ^15.0.0-0 || ^16.0.0-0"
Expand Down
10 changes: 10 additions & 0 deletions packages/enzyme-adapter-utils/src/Utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import functionName from 'function.prototype.name';
import createMountWrapper from './createMountWrapper';
import createRenderWrapper from './createRenderWrapper';
import {
Portal,
} from 'react-is';

export { createMountWrapper, createRenderWrapper };

Expand Down Expand Up @@ -94,6 +97,10 @@ export function displayNameOfNode(node) {

if (!type) return null;

if (type === Portal) {
return 'Portal';
}

return type.displayName || (typeof type === 'function' ? functionName(type) : type.name || type);
}

Expand All @@ -104,6 +111,9 @@ export function nodeTypeFromType(type) {
if (type && type.prototype && type.prototype.isReactComponent) {
return 'class';
}
if (type && type === Portal) {
return 'portal';
}
return 'function';
}

Expand Down

0 comments on commit c74acb4

Please sign in to comment.