Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions scripts/fiber/tests-failing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,7 @@ src/shared/utils/__tests__/traverseAllChildren-test.js
* should warn for using maps as children with owner info

src/test/__tests__/ReactTestUtils-test.js
* traverses children in the correct order
* should support injected wrapper components as DOM components
* should change the value of an input field
* should change the value of an input field in a component
* can scry with stateless components involved
* should set the type of the event
2 changes: 2 additions & 0 deletions scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1260,8 +1260,10 @@ src/test/__tests__/ReactTestUtils-test.js
* can scryRenderedDOMComponentsWithClass with TextComponent
* can scryRenderedDOMComponentsWithClass with className contains \n
* can scryRenderedDOMComponentsWithClass with multiple classes
* traverses children in the correct order
* should throw when attempting to use ReactTestUtils.Simulate with shallow rendering
* should not warn when simulating events with extra properties
* can scry with stateless components involved

src/test/__tests__/reactComponentExpect-test.js
* should match composite components
Expand Down
13 changes: 12 additions & 1 deletion src/test/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ var invariant = require('invariant');
var topLevelTypes = EventConstants.topLevelTypes;
var {
ClassComponent,
FunctionalComponent,
HostComponent,
HostContainer,
HostText,
} = ReactTypeOfWork;

Expand Down Expand Up @@ -80,6 +82,7 @@ function findAllInRenderedFiberTreeInternal(fiber, test) {
}
if (
fiber.tag !== ClassComponent &&
fiber.tag !== FunctionalComponent &&
fiber.tag !== HostComponent &&
fiber.tag !== HostText
) {
Expand Down Expand Up @@ -209,7 +212,15 @@ var ReactTestUtils = {
);
var internalInstance = ReactInstanceMap.get(inst);
if (internalInstance && typeof internalInstance.tag === 'number') {
return findAllInRenderedFiberTreeInternal(internalInstance, test);
var fiber = internalInstance;
var root = fiber;
while (root.return) {
root = root.return;
}
var isRootCurrent = root.tag === HostContainer && root.stateNode.current === root;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is a good way to tell that we're in a current tree. Any pitfalls?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm facing the same problem in the PR I'm working on.

// Make sure we're introspecting the current tree
var current = isRootCurrent ? fiber : fiber.alternate;
return findAllInRenderedFiberTreeInternal(current, test);
} else {
return findAllInRenderedStackTreeInternal(internalInstance, test);
}
Expand Down