From 0832509a6814ca9481224f887b1579b902e9fa71 Mon Sep 17 00:00:00 2001 From: Jaryd Carolin Date: Thu, 9 Jun 2016 16:49:40 +0200 Subject: [PATCH] Switch to classList instead of className The property className returns an object on some (possibly all?) SVG elements. The object behaves under the interface SVGAnimatedString, which does not have method "replace". typeof check conditional use of classList, object check on className Test added for SVG find by class --- src/MountedTraversal.js | 9 ++++++++- test/ReactWrapper-spec.js | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/MountedTraversal.js b/src/MountedTraversal.js index 2508265f6..83912b5c1 100644 --- a/src/MountedTraversal.js +++ b/src/MountedTraversal.js @@ -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; } diff --git a/test/ReactWrapper-spec.js b/test/ReactWrapper-spec.js index a21a9dedd..47ced4823 100644 --- a/test/ReactWrapper-spec.js +++ b/test/ReactWrapper-spec.js @@ -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( +
+ +
+ ); + expect(wrapper.find('.foo').type()).to.equal('svg'); + }); + it('should find an element based on a tag name', () => { const wrapper = mount(