Skip to content

Commit

Permalink
properly handling invalid scryRenderedDOMComponentsWithClass args (#6529
Browse files Browse the repository at this point in the history
)

properly handling invalid scryRenderedDOMComponentsWithClass args

properly handle invalid scryRenderedDOMComponentsWithClass args
  • Loading branch information
ipetez authored and jimfb committed Apr 22, 2016
1 parent 416f315 commit 9df54e0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/test/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
});
Expand Down

0 comments on commit 9df54e0

Please sign in to comment.