diff --git a/src/MountedTraversal.js b/src/MountedTraversal.js index afeb9650c..2e96561cb 100644 --- a/src/MountedTraversal.js +++ b/src/MountedTraversal.js @@ -51,8 +51,9 @@ export function instHasClassName(inst, className) { if (!isDOMComponent(inst)) { return false; } - const classes = findDOMNode(inst).className || ''; - return ` ${classes.trim()} `.indexOf(` ${className} `) > -1; + let classes = findDOMNode(inst).className || ''; + classes = classes.replace(/\s/g, ' ').trim(); + return ` ${classes} `.indexOf(` ${className} `) > -1; } export function instHasId(inst, id) { diff --git a/src/ShallowTraversal.js b/src/ShallowTraversal.js index 0a52ef7b6..6a8a9142a 100644 --- a/src/ShallowTraversal.js +++ b/src/ShallowTraversal.js @@ -28,8 +28,9 @@ export function childrenOfNode(node) { } export function hasClassName(node, className) { - const classes = propsOfNode(node).className || ''; - return ` ${classes.trim()} `.indexOf(` ${className} `) > -1; + let classes = propsOfNode(node).className || ''; + classes = classes.replace(/\s/g, ' ').trim(); + return ` ${classes} `.indexOf(` ${className} `) > -1; } export function treeForEach(tree, fn) { diff --git a/test/ReactWrapper-spec.js b/test/ReactWrapper-spec.js index 0b0da382f..a01e33a1f 100644 --- a/test/ReactWrapper-spec.js +++ b/test/ReactWrapper-spec.js @@ -901,12 +901,20 @@ describeWithDOM('mount', () => { }); it('should ignore insignificant whitespace', () => { - const className = `foo + const className = ` + foo `; const wrapper = mount(
); expect(wrapper.is('.foo')).to.equal(true); }); + it('should handle all significant whitespace', () => { + const className = `foo bar + baz`; + const wrapper = mount(
); + expect(wrapper.is('.foo.bar.baz')).to.equal(true); + }); + it('should return false when selector does not match', () => { const wrapper = mount(
); expect(wrapper.is('.foo')).to.equal(false); diff --git a/test/ShallowWrapper-spec.js b/test/ShallowWrapper-spec.js index c074d0e15..05c924fd5 100644 --- a/test/ShallowWrapper-spec.js +++ b/test/ShallowWrapper-spec.js @@ -1014,6 +1014,13 @@ describe('shallow', () => { expect(wrapper.is('.foo')).to.equal(true); }); + it('should handle all significant whitespace', () => { + const className = `foo bar + baz`; + const wrapper = shallow(
); + expect(wrapper.is('.foo.bar.baz')).to.equal(true); + }); + it('should return false when selector does not match', () => { const wrapper = shallow(
); expect(wrapper.is('.foo')).to.equal(false);