Skip to content

Commit

Permalink
[Tests] add .root() tests for #1152
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jul 6, 2018
1 parent 3070850 commit f7fee9c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4174,4 +4174,18 @@ describeWithDOM('mount', () => {
expect(divProps.onClick).to.be.a('function');
});
});

describe('.root()', () => {
it('returns the root component instance', () => {
class Fixture extends React.Component {
render() {
return <div><span /><span /></div>;
}
}
const wrapper = mount(<Fixture />);
const root = wrapper.root();
expect(root.is(Fixture)).to.equal(true);
expect(root.childAt(0).children().debug()).to.equal('<span />\n\n\n<span />');
});
});
});
14 changes: 14 additions & 0 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5088,4 +5088,18 @@ describe('shallow', () => {
expect(divProps.onClick).to.be.a('function');
});
});

describe('.root()', () => {
it('returns the root DOM node', () => {
class Fixture extends React.Component {
render() {
return <div><span /><span /></div>;
}
}
const wrapper = shallow(<Fixture />);
const root = wrapper.root();
expect(root.is('div')).to.equal(true);
expect(root.children().debug()).to.equal('<span />\n\n\n<span />');
});
});
});

0 comments on commit f7fee9c

Please sign in to comment.