Skip to content

Commit

Permalink
add tests for root renders
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Zukewich committed Aug 16, 2018
1 parent 9b06f58 commit 816f647
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,39 @@ describeWithDOM('mount', () => {
expect(spy).to.have.property('callCount', 1);
});

itIf(is('>= 16'), 'should throw when mounting Portals', () => {
const portal = createPortal(
<div className="in-portal"></div>,
document.body,
);

expect(() => mount(portal)).to.throw(
TypeError,
'ReactWrapper can only wrap valid elements',
);
});

it('should throw when mounting plain text', () => {
expect(() => mount('Foo')).to.throw(
TypeError,
'ReactWrapper can only wrap valid elements',
);
});

it('should mount built in components', () => {
expect(() => mount(<div />)).not.to.throw();
});

it('should mount composite components', () => {
class Foo extends React.Component {
render() {
return <div className="in-foo"></div>;
}
}

expect(() => mount(<Foo />)).not.to.throw();
});

describeIf(is('>= 16.3'), 'uses the isValidElementType from the Adapter to validate the prop type of Component', () => {
const Foo = () => null;
const Bar = () => null;
Expand Down
34 changes: 34 additions & 0 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import './_helpers/setupAdapters';
import {
createClass,
createContext,
createPortal,
createRef,
Fragment,
forwardRef,
Expand Down Expand Up @@ -77,6 +78,39 @@ describe('shallow', () => {
expect(wrapper.children().type()).to.equal('div');
expect(wrapper.children().props().bam).to.equal(undefined);
});

itIf(is('>= 16'), 'should throw when shallow rendering Portals', () => {
const portal = createPortal(
<div className="in-portal"></div>,
document.body,
);

expect(() => shallow(portal)).to.throw(
Error,
'ShallowWrapper can only wrap valid elements',
);
});

it('should throw when shallow rendering plain text', () => {
expect(() => shallow('Foo')).to.throw(
Error,
'ShallowWrapper can only wrap valid elements',
);
});

it('should shallow render built in components', () => {
expect(() => shallow(<div />)).not.to.throw();
});

it('should shallow render composite components', () => {
class Foo extends React.Component {
render() {
return <div className="in-foo"></div>;
}
}

expect(() => shallow(<Foo />)).not.to.throw();
});
});

describe('context', () => {
Expand Down

0 comments on commit 816f647

Please sign in to comment.