From 2fa3716d42cfe70fe61e100ce2984208a556f809 Mon Sep 17 00:00:00 2001 From: Anton Grischenko Date: Thu, 28 Jul 2016 22:56:30 +0500 Subject: [PATCH] fixed hasClassName in case className is not a string and has toString(). --- src/ShallowTraversal.js | 2 +- test/ShallowTraversal-spec.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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', () => {