Skip to content

Commit

Permalink
shallow and portal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jgzuke committed Aug 19, 2018
1 parent 4f8e75f commit 1606438
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 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,55 @@ 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 Foo = () => (
createPortal(
innerDiv,
{ nodeType: 1 },
)
);

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: { nodeType: 1 },
},
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 1606438

Please sign in to comment.