Fixed ReactTestUtils scry for TextComponents. Fixes issue #2654.
This commit is contained in:
parent
91eb2e2f99
commit
74f5b21758
|
@ -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);
|
||||
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue