@samitouri / QOS-React / commits / a9fa135fd8

[Fiber] Fix reactComponentExpect (#8258) (#8257)

* Add more reactComponentExpect tests * Implement reactComponentExpect in Fiber

Dan Abramov committed Nov 10, 2016 at 21:27 UTC a9fa135fd855391de836548c0f0ff4eab6ddb07a
3 files changed +14 -3
scripts/fiber/tests-failing.txt
-2
@@ -593,9 +593,7 @@ src/shared/utils/__tests__/traverseAllChildren-test.js
593 * should warn for using maps as children with owner info
594
595 src/test/__tests__/ReactTestUtils-test.js
596 -* traverses children in the correct order
596 * should support injected wrapper components as DOM components
597 * should change the value of an input field
598 * should change the value of an input field in a component
600 -* can scry with stateless components involved
599 * should set the type of the event
scripts/fiber/tests-passing.txt
+2
@@ -1260,8 +1260,10 @@ src/test/__tests__/ReactTestUtils-test.js
1260 * can scryRenderedDOMComponentsWithClass with TextComponent
1261 * can scryRenderedDOMComponentsWithClass with className contains \n
1262 * can scryRenderedDOMComponentsWithClass with multiple classes
1263 +* traverses children in the correct order
1264 * should throw when attempting to use ReactTestUtils.Simulate with shallow rendering
1265 * should not warn when simulating events with extra properties
1266 +* can scry with stateless components involved
1267
1268 src/test/__tests__/reactComponentExpect-test.js
1269 * should match composite components
src/test/ReactTestUtils.js
+12 -1
@@ -32,7 +32,9 @@ var invariant = require('invariant');
32 var topLevelTypes = EventConstants.topLevelTypes;
33 var {
34 ClassComponent,
35 + FunctionalComponent,
36 HostComponent,
37 + HostContainer,
38 HostText,
39 } = ReactTypeOfWork;
40
@@ -80,6 +82,7 @@ function findAllInRenderedFiberTreeInternal(fiber, test) {
82 }
83 if (
84 fiber.tag !== ClassComponent &&
85 + fiber.tag !== FunctionalComponent &&
86 fiber.tag !== HostComponent &&
87 fiber.tag !== HostText
88 ) {
@@ -209,7 +212,15 @@ var ReactTestUtils = {
212 );
213 var internalInstance = ReactInstanceMap.get(inst);
214 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);
224 } else {
225 return findAllInRenderedStackTreeInternal(internalInstance, test);
226 }