Skip to content

Commit

Permalink
Merge pull request #448 from horyd/horyd-patch-classList
Browse files Browse the repository at this point in the history
Switch to using classList instead of className
  • Loading branch information
aweary authored Jul 5, 2016
2 parents fdaeb44 + 0832509 commit e6ee9d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/MountedTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ export function instHasClassName(inst, className) {
if (!isDOMComponent(inst)) {
return false;
}
let classes = findDOMNode(inst).className || '';
const node = findDOMNode(inst);
if (node.classList) {
return node.classList.contains(className);
}
let classes = node.className || '';
if (typeof classes === 'object') {
classes = classes.baseVal;
}
classes = classes.replace(/\s/g, ' ');
return ` ${classes} `.indexOf(` ${className} `) > -1;
}
Expand Down
9 changes: 9 additions & 0 deletions test/ReactWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ describeWithDOM('mount', () => {
expect(wrapper.find('.foo').type()).to.equal('input');
});

it('should find an SVG element based on a class name', () => {
const wrapper = mount(
<div>
<svg className="foo" />
</div>
);
expect(wrapper.find('.foo').type()).to.equal('svg');
});

it('should find an element based on a tag name', () => {
const wrapper = mount(
<div>
Expand Down

0 comments on commit e6ee9d7

Please sign in to comment.