optimize className check
yiminghe committed
Jun 10, 2015 at 01:09 UTC
e704503dc78476076c9f12e5147f26b0725c1e35
2 files changed
+12
-1
src/test/ReactTestUtils.js
+1
-1
@@ -174,7 +174,7 @@ var ReactTestUtils = {
174
var instClassName = React.findDOMNode(inst).className;
175
return (
176
instClassName &&
177
- (' ' + instClassName + ' ').indexOf(' ' + className + ' ') !== -1
177
+ (('' + instClassName).split(/\s+/)).indexOf(className) !== -1
178
);
179
}
180
return false;
src/test/__tests__/ReactTestUtils-test.js
+11
@@ -187,6 +187,17 @@ describe('ReactTestUtils', function() {
187
188
});
189
190
+ it('Test scryRenderedDOMComponentsWithClass with className contains \\n', function() {
191
+ var renderedComponent = ReactTestUtils.renderIntoDocument(<div>Hello <span className={`x
192
+ y`}>Jim</span></div>);
193
+ var scryResults = ReactTestUtils.scryRenderedDOMComponentsWithClass(
194
+ renderedComponent,
195
+ 'x'
196
+ );
197
+ expect(scryResults.length).toBe(1);
198
+
199
+ });
200
+
201
it('traverses children in the correct order', function() {
202
var container = document.createElement('div');
203