Handle nested Fragments in toTree (#12106) (#12107)

This commit is contained in:
Maciej Kasprzyk
2018-01-27 15:03:27 -08:00
committed by Brandon Dail
parent 40a9e64e1f
commit ef8d6d92a2
2 changed files with 24 additions and 0 deletions
+2
View File
@@ -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,
@@ -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() {