Skip to content

Commit

Permalink
test new getNode functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbay committed Oct 24, 2016
1 parent bcf175c commit 5014baa
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/ReactWrapper-spec.jsx
Expand Up @@ -3132,6 +3132,47 @@ describeWithDOM('mount', () => {
});
});

describe('.getNode()', () => {
class Test extends React.Component {
render() {
return (
<div>
<span />
<span />
</div>
);
}
}

it('should return the wrapped component instance', () => {
const wrapper = mount(<Test />);
expect(wrapper.getNode()).to.be.an.instanceof(Test);
});

it('should throw when wrapping multiple elements', () => {
const wrapper = mount(<Test />).find('span');
expect(() => wrapper.getNode()).to.throw(Error);
});
});

describe('.getNodes()', () => {
it('should return the wrapped elements', () => {
class Test extends React.Component {
render() {
return (
<div>
<span />
<span />
</div>
);
}
}

const wrapper = mount(<Test />);
expect(wrapper.find('span').getNodes()).to.have.lengthOf(2);
});
});

describe('#single()', () => {
it('throws if run on multiple nodes', () => {
const wrapper = mount(<div><i /><i /></div>).children();
Expand Down
46 changes: 46 additions & 0 deletions test/ShallowWrapper-spec.jsx
Expand Up @@ -3718,6 +3718,52 @@ describe('shallow', () => {
});
});

describe('.getNode()', () => {
const element = (
<div>
<span />
<span />
</div>
);

class Test extends React.Component {
render() {
return element;
}
}

it('should return the wrapped element', () => {
const wrapper = shallow(<Test />);
expect(wrapper.getNode()).to.equal(element);
});

it('should throw when wrapping multiple elements', () => {
const wrapper = shallow(<Test />).find('span');
expect(() => wrapper.getNode()).to.throw(Error);
});
});

describe('.getNodes()', () => {
it('should return the wrapped elements', () => {
const one = <span />;
const two = <span />;

class Test extends React.Component {
render() {
return (
<div>
{ one }
{ two }
</div>
);
}
}

const wrapper = shallow(<Test />);
expect(wrapper.find('span').getNodes()).to.deep.equal([one, two]);
});
});

describe('out-of-band state updates', () => {
class Child extends React.Component {
render() {
Expand Down

0 comments on commit 5014baa

Please sign in to comment.