8000 Merge pull request #2695 from jsfb/fix-scry2 · gitcommituser/react@df81c99 · GitHub
[go: up one dir, main page]

Skip to content

Commit df81c99

Browse files
committed
Merge pull request facebook#2695 from jsfb/fix-scry2
Fixed ReactTestUtils scry for TextComponents. Fix
2 parents 91eb2e2 + 74f5b21 commit df81c99

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/test/ReactTestUtils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ var ReactTestUtils = {
124124
if (!renderedChildren.hasOwnProperty(key)) {
125125
continue;
126126
}
127+
if (!renderedChildren[key].getPublicInstance) {
128+
continue;
129+
}
127130
ret = ret.concat(
128131
ReactTestUtils.findAllInRenderedTree(
129132
renderedChildren[key].getPublicInstance(),
@@ -167,7 +170,9 @@ var ReactTestUtils = {
167170
var all =
168171
ReactTestUtils.scryRenderedDOMComponentsWithClass(root, className);
169172
if (all.length !== 1) {
170-
throw new Error('Did not find exactly one match for class:' + className);
173+
throw C586 new Error('Did not find exactly one match '+
174+
'(found: ' + all.length + ') for class:' + className
175+
);
171176
}
172177
return all[0];
173178
},

src/test/__tests__/ReactTestUtils-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,14 @@ describe('ReactTestUtils', function() {
110110
expect(updatedResultCausedByClick.type).toBe('a');
111111
expect(updatedResultCausedByClick.props.className).toBe('was-clicked');
112112
});
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+
});
113123
});

0 commit comments

Comments
 (0)
0