Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add children to mounted portal props #1774

Merged
merged 1 commit into from
Aug 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function elementToTree(el) {
type: Portal,
props,
key: ensureKeyOrUndefined(el.key),
ref: el.ref,
ref: el.ref || null,
instance: null,
rendered: elementToTree(el.children),
};
Expand All @@ -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 @@ -95,7 +95,7 @@ function elementToTree(el) {
type: Portal,
props,
key: ensureKeyOrUndefined(el.key),
ref: el.ref,
ref: el.ref || null,
instance: null,
rendered: elementToTree(el.children),
};
Expand All @@ -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 @@ -100,7 +100,7 @@ function elementToTree(el) {
type: Portal,
props,
key: ensureKeyOrUndefined(el.key),
ref: el.ref,
ref: el.ref || null,
instance: null,
rendered: elementToTree(el.children),
};
Expand All @@ -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
9 changes: 6 additions & 3 deletions packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function elementToTree(el) {
type: Portal,
props,
key: ensureKeyOrUndefined(el.key),
ref: el.ref,
ref: el.ref || null,
instance: null,
rendered: elementToTree(el.children),
};
Expand All @@ -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: null,
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