Skip to content

Commit

Permalink
mount: add containerInfo to Portal representations
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Aug 18, 2018
1 parent e45b365 commit 605021d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,19 @@ function toTree(vnode) {
switch (node.tag) {
case HostRoot: // 3
return childrenToTree(node.child);
case HostPortal: // 4
case HostPortal: { // 4
const { stateNode: { containerInfo } } = node;
const props = { containerInfo };
return {
nodeType: 'portal',
type: Portal,
props: {},
props,
key: ensureKeyOrUndefined(node.key),
ref: node.ref,
instance: null,
rendered: childrenToTree(node.child),
};
}
case ClassComponent:
return {
nodeType: 'class',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,19 @@ function toTree(vnode) {
switch (node.tag) {
case HostRoot: // 3
return childrenToTree(node.child);
case HostPortal: // 4
case HostPortal: { // 4
const { stateNode: { containerInfo } } = node;
const props = { containerInfo };
return {
nodeType: 'portal',
type: Portal,
props: {},
props,
key: ensureKeyOrUndefined(node.key),
ref: node.ref,
instance: null,
rendered: childrenToTree(node.child),
};
}
case ClassComponent:
return {
nodeType: 'class',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,19 @@ function toTree(vnode) {
switch (node.tag) {
case HostRoot: // 3
return childrenToTree(node.child);
case HostPortal: // 4
case HostPortal: { // 4
const { stateNode: { containerInfo } } = node;
const props = { containerInfo };
return {
nodeType: 'portal',
type: Portal,
props: {},
props,
key: ensureKeyOrUndefined(node.key),
ref: node.ref,
instance: null,
rendered: childrenToTree(node.child),
};
}
case ClassComponent:
return {
nodeType: 'class',
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 @@ -117,16 +117,19 @@ function toTree(vnode) {
switch (node.tag) {
case HostRoot: // 3
return childrenToTree(node.child);
case HostPortal: // 4
case HostPortal: { // 4
const { stateNode: { containerInfo } } = node;
const props = { containerInfo };
return {
nodeType: 'portal',
type: Portal,
props: {},
props,
key: ensureKeyOrUndefined(node.key),
ref: node.ref,
instance: null,
rendered: childrenToTree(node.child),
};
}
case ClassComponent:
return {
nodeType: 'class',
Expand Down
4 changes: 3 additions & 1 deletion packages/enzyme-test-suite/test/Adapter-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ describe('Adapter', () => {
rendered: {
nodeType: 'portal',
type: Portal,
props: {},
props: {
containerInfo: document.body,
},
key: undefined,
ref: null,
instance: null,
Expand Down
15 changes: 8 additions & 7 deletions packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ describeWithDOM('mount', () => {
const wrapper = mount(<Foo />);
expect(wrapper.debug()).to.equal(`<Foo>
<div>
<Portal>
<Portal containerInfo={{...}}>
<div className="in-portal">
InPortal
</div>
Expand All @@ -453,8 +453,9 @@ describeWithDOM('mount', () => {
</Foo>`);
});

it('should show portal container in shallow debug tree', () => {
it('should show portal container in debug tree', () => {
const containerDiv = global.document.createElement('div');
containerDiv.setAttribute('data-foo', 'bar');
const Foo = () => (
<div className="foo">
{createPortal(
Expand All @@ -467,7 +468,7 @@ describeWithDOM('mount', () => {
const wrapper = mount(<Foo />);
expect(wrapper.debug({ verbose: true })).to.equal(`<Foo>
<div className="foo">
<Portal>
<Portal containerInfo={<div data-foo="bar">...</div>}>
<div className="in-portal">
InPortal
</div>
Expand Down Expand Up @@ -496,7 +497,7 @@ describeWithDOM('mount', () => {
const wrapper = mount(<Foo />);
expect(wrapper.debug()).to.equal(`<Foo>
<div className="foo">
<Portal>
<Portal containerInfo={{...}}>
<div className="in-portal">
<div className="nested-in-portal">
<Bar />
Expand All @@ -516,7 +517,7 @@ describeWithDOM('mount', () => {

const wrapper = mount(<Foo />);
expect(wrapper.debug()).to.equal(`<Foo>
<Portal>
<Portal containerInfo={{...}}>
<div className="in-portal">
InPortal
</div>
Expand Down Expand Up @@ -1372,7 +1373,7 @@ describeWithDOM('mount', () => {
);

const wrapper = mount(<Foo />);
expect(wrapper.find('Portal').debug()).to.equal(`<Portal>
expect(wrapper.find('Portal').debug()).to.equal(`<Portal containerInfo={{...}}>
<div className="in-portal">
InPortal
</div>
Expand Down Expand Up @@ -1714,7 +1715,7 @@ describeWithDOM('mount', () => {

const wrapper = mount(<Foo />);
expect(wrapper.findWhere(node => node.type() === Portal).debug())
.to.equal(`<Portal>
.to.equal(`<Portal containerInfo={{...}}>
<div className="in-portal">
InPortal
</div>
Expand Down

0 comments on commit 605021d

Please sign in to comment.