Skip to content

Commit

Permalink
Handle nested Fragments in toTree (#12106) (#12107)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej-ka authored and aweary committed Jan 27, 2018
1 parent 482f6ef commit 4a38d6d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ReactTestRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ function toTree(node: ?Fiber) {
};
case HostText: // 6
return node.stateNode.text;
case Fragment: // 10
return toTree(node.child);
default:
invariant(
false,
Expand Down
22 changes: 22 additions & 0 deletions src/__tests__/ReactTestRenderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,28 @@ describe('ReactTestRenderer', () => {
);
});

it('toTree() handles nested Fragments', () => {
const Foo = () => (
<React.Fragment>
<React.Fragment>foo</React.Fragment>
</React.Fragment>
);
const renderer = ReactTestRenderer.create(<Foo />);
const tree = renderer.toTree();

cleanNodeOrArray(tree);

expect(prettyFormat(tree)).toEqual(
prettyFormat({
nodeType: 'component',
type: Foo,
instance: null,
props: {},
rendered: 'foo',
}),
);
});

it('toTree() handles null rendering components', () => {
class Foo extends React.Component {
render() {
Expand Down

0 comments on commit 4a38d6d

Please sign in to comment.