Fixed ReactTestUtils scry for TextComponents. Fixes issue #2654.
Jim committed
Dec 10, 2014 at 22:50 UTC
74f5b217589a351f84d050e2a45644c3ceb6427e
2 files changed
+16
-1
src/test/ReactTestUtils.js
+6
-1
@@ -124,6 +124,9 @@ var ReactTestUtils = {
124
if (!renderedChildren.hasOwnProperty(key)) {
125
continue;
126
}
127
+ if (!renderedChildren[key].getPublicInstance) {
128
+ continue;
129
+ }
130
ret = ret.concat(
131
ReactTestUtils.findAllInRenderedTree(
132
renderedChildren[key].getPublicInstance(),
@@ -167,7 +170,9 @@ var ReactTestUtils = {
170
var all =
171
ReactTestUtils.scryRenderedDOMComponentsWithClass(root, className);
172
if (all.length !== 1) {
170
- throw new Error('Did not find exactly one match for class:' + className);
173
+ throw new Error('Did not find exactly one match '+
174
+ '(found: ' + all.length + ') for class:' + className
175
+ );
176
}
177
return all[0];
178
},
src/test/__tests__/ReactTestUtils-test.js
+10
@@ -110,4 +110,14 @@ describe('ReactTestUtils', function() {
110
expect(updatedResultCausedByClick.type).toBe('a');
111
expect(updatedResultCausedByClick.props.className).toBe('was-clicked');
112
});
113
+
114
+ it('Test scryRenderedDOMComponentsWithClass with TextComponent', function() {
115
+ var renderedComponent = ReactTestUtils.renderIntoDocument(<div>Hello <span>Jim</span></div>);
116
+ var scryResults = ReactTestUtils.scryRenderedDOMComponentsWithClass(
117
+ renderedComponent,
118
+ 'NonExistantClass'
119
+ );
120
+ expect(scryResults.length).toBe(0);
121
+
122
+ });
123
});