Skip to content

Commit

Permalink
optimize className check
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe committed Jun 9, 2015
1 parent 61d8de3 commit e704503
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/test/ReactTestUtils.js
Expand Up @@ -174,7 +174,7 @@ var ReactTestUtils = {
var instClassName = React.findDOMNode(inst).className;
return (
instClassName &&
(' ' + instClassName + ' ').indexOf(' ' + className + ' ') !== -1
(('' + instClassName).split(/\s+/)).indexOf(className) !== -1
);
}
return false;
Expand Down
11 changes: 11 additions & 0 deletions src/test/__tests__/ReactTestUtils-test.js
Expand Up @@ -187,6 +187,17 @@ describe('ReactTestUtils', function() {

});

it('Test scryRenderedDOMComponentsWithClass with className contains \\n', function() {
var renderedComponent = ReactTestUtils.renderIntoDocument(<div>Hello <span className={`x
y`}>Jim</span></div>);
var scryResults = ReactTestUtils.scryRenderedDOMComponentsWithClass(
renderedComponent,
'x'
);
expect(scryResults.length).toBe(1);

});

it('traverses children in the correct order', function() {
var container = document.createElement('div');

Expand Down

3 comments on commit e704503

@gpbl
Copy link

@gpbl gpbl commented on e704503 Sep 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is breaking a test where I check multiple classnames, e.g. scryRenderedDOMComponentsWithClass(root, "classA classB"). imho we should split className into an array and loop over into its elements.

@bloodyowl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't seem like an optimisation as you unnecessarily create an array, instead of simply manipulating strings

@gpbl
Copy link

@gpbl gpbl commented on e704503 Sep 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed i'm not suggesting an optimization - I'd keep scryRenderedDOMComponentsWithClass working with multiple classes. Better said, what is className? The value of the className attribute as in React <=0.13 or a single css class as in the rc1?

Please sign in to comment.