Skip to content

Commit

Permalink
fixed hasClassName in case className is not a string and has toString().
Browse files Browse the repository at this point in the history
  • Loading branch information
f0rmat1k committed Jul 28, 2016
1 parent f5762e4 commit 2fa3716
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ShallowTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions test/ShallowTraversal-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (<div className={classes} />);
expect(hasClassName(node, 'foo-bar')).to.equal(true);
});
});

describe('nodeHasProperty', () => {
Expand Down

0 comments on commit 2fa3716

Please sign in to comment.