From 4bb83d237e2a9c20e50747f967eb0389de7125b1 Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Wed, 7 Oct 2015 17:18:20 -0700 Subject: [PATCH] Don't break on SVG tags in scryRenderedDOMComponentsWithClass Fixes #5076. --- src/test/ReactTestUtils.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/test/ReactTestUtils.js b/src/test/ReactTestUtils.js index 2782df32da10d..b754fd8f9fd71 100644 --- a/src/test/ReactTestUtils.js +++ b/src/test/ReactTestUtils.js @@ -99,8 +99,6 @@ var ReactTestUtils = { }, isDOMComponent: function(inst) { - // TODO: Fix this heuristic. It's just here because composites can currently - // pretend to be DOM components. return !!(inst && inst.nodeType === 1 && inst.tagName); }, @@ -186,9 +184,14 @@ var ReactTestUtils = { } return ReactTestUtils.findAllInRenderedTree(root, function(inst) { if (ReactTestUtils.isDOMComponent(inst)) { - var classList = ReactDOM.findDOMNode(inst).className.split(/\s+/); - return classNames.every(function(className) { - return classList.indexOf(className) !== -1; + var className = inst.className; + if (typeof className !== 'string') { + // SVG, probably. + className = inst.getAttribute('class') || ''; + } + var classList = className.split(/\s+/); + return classNames.every(function(name) { + return classList.indexOf(name) !== -1; }); } return false;