mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Fixed ReactTestUtils scry for TextComponents. Fixes issue #2654.
This commit is contained in:
@@ -124,6 +124,9 @@ var ReactTestUtils = {
|
||||
if (!renderedChildren.hasOwnProperty(key)) {
|
||||
continue;
|
||||
}
|
||||
if (!renderedChildren[key].getPublicInstance) {
|
||||
continue;
|
||||
}
|
||||
ret = ret.concat(
|
||||
ReactTestUtils.findAllInRenderedTree(
|
||||
renderedChildren[key].getPublicInstance(),
|
||||
@@ -167,7 +170,9 @@ var ReactTestUtils = {
|
||||
var all =
|
||||
ReactTestUtils.scryRenderedDOMComponentsWithClass(root, className);
|
||||
if (all.length !== 1) {
|
||||
throw new Error('Did not find exactly one match for class:' + className);
|
||||
throw new Error('Did not find exactly one match '+
|
||||
'(found: ' + all.length + ') for class:' + className
|
||||
);
|
||||
}
|
||||
return all[0];
|
||||
},
|
||||
|
||||
@@ -110,4 +110,14 @@ describe('ReactTestUtils', function() {
|
||||
expect(updatedResultCausedByClick.type).toBe('a');
|
||||
expect(updatedResultCausedByClick.props.className).toBe('was-clicked');
|
||||
});
|
||||
|
||||
it('Test scryRenderedDOMComponentsWithClass with TextComponent', function() {
|
||||
var renderedComponent = ReactTestUtils.renderIntoDocument(<div>Hello <span>Jim</span></div>);
|
||||
var scryResults = ReactTestUtils.scryRenderedDOMComponentsWithClass(
|
||||
renderedComponent,
|
||||
'NonExistantClass'
|
||||
);
|
||||
expect(scryResults.length).toBe(0);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user