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
(cherry picked from commit 9df54e0)
  • Loading branch information
ipetez authored and zpao committed Apr 28, 2016
1 parent c98f0e6 commit 2606966
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 2606966

Please sign in to comment.