From 2606966b43c1b5cab91e088aaad7faf433ffb04b Mon Sep 17 00:00:00 2001 From: Ike Peters Date: Thu, 21 Apr 2016 17:09:04 -0700 Subject: [PATCH] properly handling invalid scryRenderedDOMComponentsWithClass args (#6529) properly handling invalid scryRenderedDOMComponentsWithClass args properly handle invalid scryRenderedDOMComponentsWithClass args (cherry picked from commit 9df54e0fce209a60c49145da9fc3f15b2671e719) --- src/test/ReactTestUtils.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/test/ReactTestUtils.js b/src/test/ReactTestUtils.js index 20f2cb5adb21c..0e6b19150f32d 100644 --- a/src/test/ReactTestUtils.js +++ b/src/test/ReactTestUtils.js @@ -178,9 +178,6 @@ var ReactTestUtils = { * @return {array} an array of all the matches. */ scryRenderedDOMComponentsWithClass: function(root, classNames) { - if (!Array.isArray(classNames)) { - classNames = classNames.split(/\s+/); - } return ReactTestUtils.findAllInRenderedTree(root, function(inst) { if (ReactTestUtils.isDOMComponent(inst)) { var className = inst.className; @@ -189,6 +186,15 @@ var ReactTestUtils = { className = inst.getAttribute('class') || ''; } var classList = className.split(/\s+/); + + if (!Array.isArray(classNames)) { + invariant( + classNames !== undefined, + 'TestUtils.scryRenderedDOMComponentsWithClass expects a ' + + 'className as a second argument.' + ); + classNames = classNames.split(/\s+/); + } return classNames.every(function(name) { return classList.indexOf(name) !== -1; });