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 40a9e64 commit ef8d6d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/react-test-renderer/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
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 ef8d6d9

Please sign in to comment.