diff --git a/src/ShallowTraversal.js b/src/ShallowTraversal.js index 350c4a1d4..7ecd4dafe 100644 --- a/src/ShallowTraversal.js +++ b/src/ShallowTraversal.js @@ -27,7 +27,7 @@ export function childrenOfNode(node) { export function hasClassName(node, className) { let classes = propsOfNode(node).className || ''; - classes = classes.replace(/\s/g, ' '); + classes = String(classes).replace(/\s/g, ' '); return ` ${classes} `.indexOf(` ${className} `) > -1; } diff --git a/test/ShallowTraversal-spec.js b/test/ShallowTraversal-spec.js index f07dab051..0a667cd80 100644 --- a/test/ShallowTraversal-spec.js +++ b/test/ShallowTraversal-spec.js @@ -59,6 +59,12 @@ describe('ShallowTraversal', () => { expect(hasClassName(node, 'foo-bar')).to.equal(true); }); + it('should work if className has a function in toString property', () => { + function classes() {} + classes.toString = () => 'foo-bar'; + const node = (
); + expect(hasClassName(node, 'foo-bar')).to.equal(true); + }); }); describe('nodeHasProperty', () => {