Skip to content

Commit a9fa135

Browse files
authored
[Fiber] Fix reactComponentExpect (#8258) (#8257)
* Add more reactComponentExpect tests * Implement reactComponentExpect in Fiber
1 parent 3e26804 commit a9fa135

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

scripts/fiber/tests-failing.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,7 @@ src/shared/utils/__tests__/traverseAllChildren-test.js
593593
* should warn for using maps as children with owner info
594594

595595
src/test/__tests__/ReactTestUtils-test.js
596-
* traverses children in the correct order
597596
* should support injected wrapper components as DOM components
598597
* should change the value of an input field
599598
* should change the value of an input field in a component
600-
* can scry with stateless components involved
601599
* should set the type of the event

scripts/fiber/tests-passing.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,8 +1260,10 @@ src/test/__tests__/ReactTestUtils-test.js
12601260
* can scryRenderedDOMComponentsWithClass with TextComponent
12611261
* can scryRenderedDOMComponentsWithClass with className contains \n
12621262
* can scryRenderedDOMComponentsWithClass with multiple classes
1263+
* traverses children in the correct order
12631264
* should throw when attempting to use ReactTestUtils.Simulate with shallow rendering
12641265
* should not warn when simulating events with extra properties
1266+
* can scry with stateless components involved
12651267

12661268
src/test/__tests__/reactComponentExpect-test.js
12671269
* should match composite components

src/test/ReactTestUtils.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ var invariant = require('invariant');
3232
var topLevelTypes = EventConstants.topLevelTypes;
3333
var {
3434
ClassComponent,
35+
FunctionalComponent,
3536
HostComponent,
37+
HostContainer,
3638
HostText,
3739
} = ReactTypeOfWork;
3840

@@ -80,6 +82,7 @@ function findAllInRenderedFiberTreeInternal(fiber, test) {
8082
}
8183
if (
8284
fiber.tag !== ClassComponent &&
85+
fiber.tag !== FunctionalComponent &&
8386
fiber.tag !== HostComponent &&
8487
fiber.tag !== HostText
8588
) {
@@ -209,7 +212,15 @@ var ReactTestUtils = {
209212
);
210213
var internalInstance = ReactInstanceMap.get(inst);
211214
if (internalInstance && typeof internalInstance.tag === 'number') {
212-
return findAllInRenderedFiberTreeInternal(internalInstance, test);
215+
var fiber = internalInstance;
216+
var root = fiber;
217+
while (root.return) {
218+
root = root.return;
219+
}
220+
var isRootCurrent = root.tag === HostContainer && root.stateNode.current === root;
221+
// Make sure we're introspecting the current tree
222+
var current = isRootCurrent ? fiber : fiber.alternate;
223+
return findAllInRenderedFiberTreeInternal(current, test);
213224
} else {
214225
return findAllInRenderedStackTreeInternal(internalInstance, test);
215226
}

0 commit comments

Comments
 (0)