Skip to content

Commit f7fee9c

Browse files
committed
[Tests] add .root() tests for #1152
1 parent 3070850 commit f7fee9c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

packages/enzyme-test-suite/test/ReactWrapper-spec.jsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4174,4 +4174,18 @@ describeWithDOM('mount', () => {
41744174
expect(divProps.onClick).to.be.a('function');
41754175
});
41764176
});
4177+
4178+
describe('.root()', () => {
4179+
it('returns the root component instance', () => {
4180+
class Fixture extends React.Component {
4181+
render() {
4182+
return <div><span /><span /></div>;
4183+
}
4184+
}
4185+
const wrapper = mount(<Fixture />);
4186+
const root = wrapper.root();
4187+
expect(root.is(Fixture)).to.equal(true);
4188+
expect(root.childAt(0).children().debug()).to.equal('<span />\n\n\n<span />');
4189+
});
4190+
});
41774191
});

packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5088,4 +5088,18 @@ describe('shallow', () => {
50885088
expect(divProps.onClick).to.be.a('function');
50895089
});
50905090
});
5091+
5092+
describe('.root()', () => {
5093+
it('returns the root DOM node', () => {
5094+
class Fixture extends React.Component {
5095+
render() {
5096+
return <div><span /><span /></div>;
5097+
}
5098+
}
5099+
const wrapper = shallow(<Fixture />);
5100+
const root = wrapper.root();
5101+
expect(root.is('div')).to.equal(true);
5102+
expect(root.children().debug()).to.equal('<span />\n\n\n<span />');
5103+
});
5104+
});
50915105
});

0 commit comments

Comments
 (0)