Fixed ReactTestUtils scry for TextComponents. Fixes issue #2654.

This commit is contained in:
Jim
2014-12-11 13:12:35 -08:00
parent 91eb2e2f99
commit 74f5b21758
2 changed files with 16 additions and 1 deletions
+6 -1
View File
@@ -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];
},
+10
View File
@@ -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);
});
});