From 5014baacf110df6a395483dcdf1d728f7dcb07f6 Mon Sep 17 00:00:00 2001 From: Justin Bay Date: Tue, 27 Sep 2016 21:37:22 -0400 Subject: [PATCH] test new getNode functions --- test/ReactWrapper-spec.jsx | 41 ++++++++++++++++++++++++++++++++ test/ShallowWrapper-spec.jsx | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/test/ReactWrapper-spec.jsx b/test/ReactWrapper-spec.jsx index 3d3f9eb94..a73ab0c55 100644 --- a/test/ReactWrapper-spec.jsx +++ b/test/ReactWrapper-spec.jsx @@ -3132,6 +3132,47 @@ describeWithDOM('mount', () => { }); }); + describe('.getNode()', () => { + class Test extends React.Component { + render() { + return ( +
+ + +
+ ); + } + } + + it('should return the wrapped component instance', () => { + const wrapper = mount(); + expect(wrapper.getNode()).to.be.an.instanceof(Test); + }); + + it('should throw when wrapping multiple elements', () => { + const wrapper = mount().find('span'); + expect(() => wrapper.getNode()).to.throw(Error); + }); + }); + + describe('.getNodes()', () => { + it('should return the wrapped elements', () => { + class Test extends React.Component { + render() { + return ( +
+ + +
+ ); + } + } + + const wrapper = mount(); + expect(wrapper.find('span').getNodes()).to.have.lengthOf(2); + }); + }); + describe('#single()', () => { it('throws if run on multiple nodes', () => { const wrapper = mount(
).children(); diff --git a/test/ShallowWrapper-spec.jsx b/test/ShallowWrapper-spec.jsx index 48e21253f..fa3710bf9 100644 --- a/test/ShallowWrapper-spec.jsx +++ b/test/ShallowWrapper-spec.jsx @@ -3718,6 +3718,52 @@ describe('shallow', () => { }); }); + describe('.getNode()', () => { + const element = ( +
+ + +
+ ); + + class Test extends React.Component { + render() { + return element; + } + } + + it('should return the wrapped element', () => { + const wrapper = shallow(); + expect(wrapper.getNode()).to.equal(element); + }); + + it('should throw when wrapping multiple elements', () => { + const wrapper = shallow().find('span'); + expect(() => wrapper.getNode()).to.throw(Error); + }); + }); + + describe('.getNodes()', () => { + it('should return the wrapped elements', () => { + const one = ; + const two = ; + + class Test extends React.Component { + render() { + return ( +
+ { one } + { two } +
+ ); + } + } + + const wrapper = shallow(); + expect(wrapper.find('span').getNodes()).to.deep.equal([one, two]); + }); + }); + describe('out-of-band state updates', () => { class Child extends React.Component { render() {