Skip to content

Commit

Permalink
[enzyme-adapter-react-16*] mount: add children prop
Browse files Browse the repository at this point in the history
  • Loading branch information
jgzuke authored and ljharb committed Aug 18, 2018
1 parent a47f2ba commit 422dd30
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ function toTree(vnode) {
case HostRoot: // 3
return childrenToTree(node.child);
case HostPortal: { // 4
const { stateNode: { containerInfo } } = node;
const props = { containerInfo };
const {
stateNode: { containerInfo },
memoizedProps: children,
} = node;
const props = { containerInfo, children };
return {
nodeType: 'portal',
type: Portal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,11 @@ function toTree(vnode) {
case HostRoot: // 3
return childrenToTree(node.child);
case HostPortal: { // 4
const { stateNode: { containerInfo } } = node;
const props = { containerInfo };
const {
stateNode: { containerInfo },
memoizedProps: children,
} = node;
const props = { containerInfo, children };
return {
nodeType: 'portal',
type: Portal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ function toTree(vnode) {
case HostRoot: // 3
return childrenToTree(node.child);
case HostPortal: { // 4
const { stateNode: { containerInfo } } = node;
const props = { containerInfo };
const {
stateNode: { containerInfo },
memoizedProps: children,
} = node;
const props = { containerInfo, children };
return {
nodeType: 'portal',
type: Portal,
Expand Down
7 changes: 5 additions & 2 deletions packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ function toTree(vnode) {
case HostRoot: // 3
return childrenToTree(node.child);
case HostPortal: { // 4
const { stateNode: { containerInfo } } = node;
const props = { containerInfo };
const {
stateNode: { containerInfo },
memoizedProps: children,
} = node;
const props = { containerInfo, children };
return {
nodeType: 'portal',
type: Portal,
Expand Down
56 changes: 55 additions & 1 deletion packages/enzyme-test-suite/test/Adapter-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,10 @@ describe('Adapter', () => {
const document = jsdom.jsdom();
const options = { mode: 'mount' };
const renderer = adapter.createRenderer(options);
const innerDiv = <div className="Foo">Hello World!</div>;
const Foo = () => (
createPortal(
<div className="Foo">Hello World!</div>,
innerDiv,
document.body,
)
);
Expand All @@ -219,6 +220,9 @@ describe('Adapter', () => {

const node = renderer.getNode();

const { rendered: { props: { children } } } = node;
expect(children).to.equal(innerDiv);

cleanNode(node);

expect(prettyFormat(node)).to.equal(prettyFormat({
Expand Down Expand Up @@ -250,6 +254,56 @@ describe('Adapter', () => {
}));
});

itIf(is('>= 16'), 'shallow renders react portals', () => {
const options = { mode: 'shallow' };
const renderer = adapter.createRenderer(options);
const innerDiv = <div className="Foo">Hello World!</div>;
const containerDiv = { nodeType: 1 };
const Foo = () => (
createPortal(
innerDiv,
containerDiv,
)
);

renderer.render(<Foo />);

const node = renderer.getNode();

const { rendered: { props: { children } } } = node;
expect(children).to.equal(innerDiv);

cleanNode(node);

expect(prettyFormat(node)).to.equal(prettyFormat({
nodeType: 'function',
type: Foo,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: {
nodeType: 'portal',
type: Portal,
props: {
containerInfo: containerDiv,
},
key: undefined,
ref: undefined,
instance: null,
rendered: {
nodeType: 'host',
type: 'div',
props: { className: 'Foo' },
key: undefined,
ref: null,
instance: null,
rendered: 'Hello World!',
},
},
}));
});

itIf(is('> 0.13'), 'renders simple components returning host components', () => {
const options = { mode: 'mount' };
const renderer = adapter.createRenderer(options);
Expand Down

0 comments on commit 422dd30

Please sign in to comment.