@samitouri / QOS-React / commits / 9df54e0fce

properly handling invalid scryRenderedDOMComponentsWithClass args (#6529)

properly handling invalid scryRenderedDOMComponentsWithClass args properly handle invalid scryRenderedDOMComponentsWithClass args

Ike Peters committed Apr 21, 2016 at 17:09 UTC 9df54e0fce209a60c49145da9fc3f15b2671e719
1 file changed +9 -3
src/test/ReactTestUtils.js
+9 -3
@@ -178,9 +178,6 @@ var ReactTestUtils = {
178 * @return {array} an array of all the matches.
179 */
180 scryRenderedDOMComponentsWithClass: function(root, classNames) {
181 - if (!Array.isArray(classNames)) {
182 - classNames = classNames.split(/\s+/);
183 - }
181 return ReactTestUtils.findAllInRenderedTree(root, function(inst) {
182 if (ReactTestUtils.isDOMComponent(inst)) {
183 var className = inst.className;
@@ -189,6 +186,15 @@ var ReactTestUtils = {
186 className = inst.getAttribute('class') || '';
187 }
188 var classList = className.split(/\s+/);
189 +
190 + if (!Array.isArray(classNames)) {
191 + invariant(
192 + classNames !== undefined,
193 + 'TestUtils.scryRenderedDOMComponentsWithClass expects a ' +
194 + 'className as a second argument.'
195 + );
196 + classNames = classNames.split(/\s+/);
197 + }
198 return classNames.every(function(name) {
199 return classList.indexOf(name) !== -1;
200 });