diff --git a/src/ReactWrapper.jsx b/src/ReactWrapper.jsx index 21fa7e1a3..63d1a6f35 100644 --- a/src/ReactWrapper.jsx +++ b/src/ReactWrapper.jsx @@ -29,7 +29,6 @@ import { typeOfNode, displayNameOfNode, ITERATOR_SYMBOL, - isFunctionalComponent, } from './Utils'; import { debugInsts, @@ -139,13 +138,7 @@ class ReactWrapper { * @returns {DOMComponent} */ getDOMNode() { - return this.single('getDOMNode', (n) => { - if (isFunctionalComponent(n)) { - throw new TypeError('Method “getDOMNode” cannot be used on functional components.'); - } - - return findDOMNode(n); - }); + return this.single('getDOMNode', findDOMNode); } /** diff --git a/test/ReactWrapper-spec.jsx b/test/ReactWrapper-spec.jsx index f6eb798a3..754420f99 100644 --- a/test/ReactWrapper-spec.jsx +++ b/test/ReactWrapper-spec.jsx @@ -2109,7 +2109,21 @@ describeWithDOM('mount', () => { }); }); - context('When using a Composite component', () => { + describeIf(!REACT013, 'with stateless components', () => { + it('should return whether or not node has a certain class', () => { + const Foo = () =>
; + const wrapper = mount(); + + expect(wrapper.hasClass('foo')).to.equal(true); + expect(wrapper.hasClass('bar')).to.equal(true); + expect(wrapper.hasClass('baz')).to.equal(true); + expect(wrapper.hasClass('some-long-string')).to.equal(true); + expect(wrapper.hasClass('FoOo')).to.equal(true); + expect(wrapper.hasClass('doesnt-exist')).to.equal(false); + }); + }); + + context('When using a Composite class component', () => { it('should return whether or not node has a certain class', () => { class Foo extends React.Component { render() { @@ -3389,11 +3403,28 @@ describeWithDOM('mount', () => { }); describeIf(!REACT013, 'stateless components', () => { - const SFC = () => (
); + const SFC = () => ( +
+
+ + +
+
+ ); - it('should throw when wrapping an SFC', () => { + it('should return the outer most DOMComponent of the root wrapper', () => { const wrapper = mount(); - expect(() => wrapper.getDOMNode()).to.throw(TypeError, 'Method “getDOMNode” cannot be used on functional components.'); + expect(wrapper.getDOMNode()).to.have.property('className', 'outer'); + }); + + it('should return the outer most DOMComponent of the inner div wrapper', () => { + const wrapper = mount(); + expect(wrapper.find('.inner').getDOMNode()).to.have.property('className', 'inner'); + }); + + it('should throw when wrapping multiple elements', () => { + const wrapper = mount().find('span'); + expect(() => wrapper.getDOMNode()).to.throw(Error); }); }); });