Skip to content

Commit

Permalink
[Tests] fix test arrangement
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Aug 31, 2018
1 parent 171e952 commit 4404e3c
Showing 1 changed file with 79 additions and 79 deletions.
158 changes: 79 additions & 79 deletions packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5610,6 +5610,85 @@ describeWithDOM('mount', () => {

expect(document.body.childNodes).to.have.lengthOf(0);
});

describeIf(is('> 0.13'), 'stateless function components', () => {
it('attaches and stuff', () => {
const Foo = () => <div className="in-foo" />;

const div = global.document.createElement('div');
const initialBodyChildren = document.body.childNodes.length;
global.document.body.appendChild(div);

expect(document.body.childNodes).to.have.lengthOf(initialBodyChildren + 1);
expect(div.childNodes).to.have.lengthOf(0);

const wrapper = mount(<Foo />, { attachTo: div });

expect(wrapper.find('.in-foo')).to.have.lengthOf(1);
expect(document.body.childNodes).to.have.lengthOf(initialBodyChildren + 1);
expect(div.childNodes).to.have.lengthOf(1);

wrapper.detach();

expect(document.body.childNodes).to.have.lengthOf(initialBodyChildren + 1);
expect(div.childNodes).to.have.lengthOf(0);

global.document.body.removeChild(div);

expect(document.body.childNodes).to.have.lengthOf(initialBodyChildren);
expect(div.childNodes).to.have.lengthOf(0);
});

it('allows for multiple attaches/detaches on same node', () => {
const Foo = () => <div className="in-foo" />;
const Bar = () => <div className="in-bar" />;

let wrapper;
const div = global.document.createElement('div');
const initialBodyChildren = document.body.childNodes.length;
global.document.body.appendChild(div);

expect(document.body.childNodes).to.have.lengthOf(initialBodyChildren + 1);
expect(div.childNodes).to.have.lengthOf(0);

wrapper = mount(<Foo />, { attachTo: div });

expect(wrapper.find('.in-foo')).to.have.lengthOf(1);
expect(document.body.childNodes).to.have.lengthOf(initialBodyChildren + 1);
expect(div.childNodes).to.have.lengthOf(1);

wrapper.detach();

wrapper = mount(<Bar />, { attachTo: div });

expect(wrapper.find('.in-bar')).to.have.lengthOf(1);
expect(document.body.childNodes).to.have.lengthOf(initialBodyChildren + 1);
expect(div.childNodes).to.have.lengthOf(1);

wrapper.detach();

expect(document.body.childNodes).to.have.lengthOf(initialBodyChildren + 1);
expect(div.childNodes).to.have.lengthOf(0);

global.document.body.removeChild(div);

expect(document.body.childNodes).to.have.lengthOf(initialBodyChildren + 0);
expect(div.childNodes).to.have.lengthOf(0);
});

it('will attach to the body successfully', () => {
const Bar = () => <div className="in-bar" />;

const wrapper = mount(<Bar />, { attachTo: document.body });

expect(wrapper.find('.in-bar')).to.have.lengthOf(1);
expect(document.body.childNodes).to.have.lengthOf(1);

wrapper.detach();

expect(document.body.childNodes).to.have.lengthOf(0);
});
});
});

it('works with class components that return null', () => {
Expand Down Expand Up @@ -5744,85 +5823,6 @@ describeWithDOM('mount', () => {
expect(spy).to.have.property('callCount', 0);
expect(spy2).to.have.property('callCount', 0);
});

describeIf(is('> 0.13'), 'stateless function components', () => {
it('attaches and stuff', () => {
const Foo = () => <div className="in-foo" />;

const div = global.document.createElement('div');
const initialBodyChildren = document.body.childNodes.length;
global.document.body.appendChild(div);

expect(document.body.childNodes).to.have.lengthOf(initialBodyChildren + 1);
expect(div.childNodes).to.have.lengthOf(0);

const wrapper = mount(<Foo />, { attachTo: div });

expect(wrapper.find('.in-foo')).to.have.lengthOf(1);
expect(document.body.childNodes).to.have.lengthOf(initialBodyChildren + 1);
expect(div.childNodes).to.have.lengthOf(1);

wrapper.detach();

expect(document.body.childNodes).to.have.lengthOf(initialBodyChildren + 1);
expect(div.childNodes).to.have.lengthOf(0);

global.document.body.removeChild(div);

expect(document.body.childNodes).to.have.lengthOf(initialBodyChildren);
expect(div.childNodes).to.have.lengthOf(0);
});

it('allows for multiple attaches/detaches on same node', () => {
const Foo = () => <div className="in-foo" />;
const Bar = () => <div className="in-bar" />;

let wrapper;
const div = global.document.createElement('div');
const initialBodyChildren = document.body.childNodes.length;
global.document.body.appendChild(div);

expect(document.body.childNodes).to.have.lengthOf(initialBodyChildren + 1);
expect(div.childNodes).to.have.lengthOf(0);

wrapper = mount(<Foo />, { attachTo: div });

expect(wrapper.find('.in-foo')).to.have.lengthOf(1);
expect(document.body.childNodes).to.have.lengthOf(initialBodyChildren + 1);
expect(div.childNodes).to.have.lengthOf(1);

wrapper.detach();

wrapper = mount(<Bar />, { attachTo: div });

expect(wrapper.find('.in-bar')).to.have.lengthOf(1);
expect(document.body.childNodes).to.have.lengthOf(initialBodyChildren + 1);
expect(div.childNodes).to.have.lengthOf(1);

wrapper.detach();

expect(document.body.childNodes).to.have.lengthOf(initialBodyChildren + 1);
expect(div.childNodes).to.have.lengthOf(0);

global.document.body.removeChild(div);

expect(document.body.childNodes).to.have.lengthOf(initialBodyChildren + 0);
expect(div.childNodes).to.have.lengthOf(0);
});

it('will attach to the body successfully', () => {
const Bar = () => <div className="in-bar" />;

const wrapper = mount(<Bar />, { attachTo: document.body });

expect(wrapper.find('.in-bar')).to.have.lengthOf(1);
expect(document.body.childNodes).to.have.lengthOf(1);

wrapper.detach();

expect(document.body.childNodes).to.have.lengthOf(0);
});
});
});

describe('.containsMatchingElement(node)', () => {
Expand Down

0 comments on commit 4404e3c

Please sign in to comment.