Skip to content

Commit

Permalink
[Tests] make mount/shallow Portal tests consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
jgzuke authored and ljharb committed Aug 18, 2018
1 parent 3bc5de2 commit 7fcacb7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 59 deletions.
87 changes: 31 additions & 56 deletions packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1096,32 +1096,6 @@ describeWithDOM('mount', () => {
expect(wrapper).to.have.lengthOf(2);
});

itIf(is('>= 16'), 'should find elements through portals', () => {
const containerDiv = global.document.createElement('div');
class FooPortal extends React.Component {
render() {
return createPortal(
this.props.children,
containerDiv,
);
}
}


const wrapper = mount((
<FooPortal>
<h1>Successful Portal!</h1>
<span />
</FooPortal>
));

expect(wrapper.find('h1')).to.have.lengthOf(1);

expect(wrapper.find('span')).to.have.lengthOf(1);

expect(containerDiv.querySelectorAll('h1')).to.have.lengthOf(1);
});

it('should support object property selectors', () => {
const wrapper = mount((
<div>
Expand Down Expand Up @@ -1201,23 +1175,6 @@ describeWithDOM('mount', () => {
expect(wrapper.find('[data-foo="bar baz quz"]')).to.have.lengthOf(0);
});

itIf(is('>= 16'), 'should find elements through portals', () => {
const containerDiv = global.document.createElement('div');

class FooPortal extends React.Component {
render() {
return createPortal(
this.props.children,
containerDiv,
);
}
}

const wrapper = mount(<FooPortal><h1>Successful Portal!</h1></FooPortal>);
expect(wrapper.find('h1')).to.have.lengthOf(1);
expect(containerDiv.querySelectorAll('h1')).to.have.lengthOf(1);
});

describeIf(is('> 0.13'), 'stateless function components', () => {
it('should find a component based on a constructor', () => {
const Foo = () => <div />;
Expand Down Expand Up @@ -1361,7 +1318,7 @@ describeWithDOM('mount', () => {
});
});

itIf(is('>= 16'), 'should find mounted portals by name', () => {
itIf(is('>= 16'), 'should find portals by name', () => {
const containerDiv = global.document.createElement('div');
const Foo = () => (
<div>
Expand All @@ -1373,11 +1330,33 @@ describeWithDOM('mount', () => {
);

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

expect(wrapper.find('Portal')).to.have.lengthOf(1);
});

itIf(is('>= 16'), 'should find elements through portals', () => {
const containerDiv = global.document.createElement('div');
class FooPortal extends React.Component {
render() {
return createPortal(
this.props.children,
containerDiv,
);
}
}

const wrapper = mount((
<FooPortal>
<h1>Successful Portal!</h1>
<span />
</FooPortal>
));

expect(wrapper.find('h1')).to.have.lengthOf(1);

expect(wrapper.find('span')).to.have.lengthOf(1);

expect(containerDiv.querySelectorAll('h1')).to.have.lengthOf(1);
});
});

Expand Down Expand Up @@ -1702,7 +1681,7 @@ describeWithDOM('mount', () => {
expect(spy).to.have.property('callCount', 2);
});

itIf(is('>= 16'), 'should find mounted portals by react-is Portal type', () => {
itIf(is('>= 16'), 'should find portals by react-is Portal type', () => {
const containerDiv = global.document.createElement('div');
const Foo = () => (
<div>
Expand All @@ -1714,12 +1693,8 @@ describeWithDOM('mount', () => {
);

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

expect(wrapper.findWhere(node => node.type() === Portal)).to.have.lengthOf(1);
});
});

Expand Down
9 changes: 6 additions & 3 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1165,11 +1165,12 @@ describe('shallow', () => {
});

itIf(is('>= 16'), 'should find portals by name', () => {
const containerDiv = { nodeType: 1 };
const Foo = () => (
<div>
{createPortal(
<div className="in-portal">InPortal</div>,
{ nodeType: 1 },
containerDiv,
)}
</div>
);
Expand All @@ -1180,14 +1181,15 @@ describe('shallow', () => {
});

itIf(is('>= 16'), 'should find elements through portals', () => {
const containerDiv = { nodeType: 1 };
const Foo = () => (
<div>
{createPortal(
<div>
<h1>Successful Portal!</h1>
<span />
</div>,
{ nodeType: 1 },
containerDiv,
)}
</div>
);
Expand Down Expand Up @@ -1495,11 +1497,12 @@ describe('shallow', () => {
});

itIf(is('>= 16'), 'should find portals by react-is Portal type', () => {
const containerDiv = { nodeType: 1 };
const Foo = () => (
<div>
{createPortal(
<div className="in-portal">InPortal</div>,
{ nodeType: 1 },
containerDiv,
)}
</div>
);
Expand Down

0 comments on commit 7fcacb7

Please sign in to comment.