Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#46255 react-test-renderer: add array retur…
Browse files Browse the repository at this point in the history
…n types for fragment components by @AlexLisenkov
  • Loading branch information
AlexLisenkov committed Aug 3, 2020
1 parent 6e50238 commit 68c3aea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions types/react-test-renderer/index.d.ts
Expand Up @@ -24,7 +24,7 @@ export type ReactTestRendererNode = ReactTestRendererJSON | string;
export interface ReactTestRendererTree extends ReactTestRendererJSON {
nodeType: 'component' | 'host';
instance: any;
rendered: null | ReactTestRendererTree;
rendered: null | ReactTestRendererTree | ReactTestRendererTree[];
}
export interface ReactTestInstance {
instance: any;
Expand All @@ -42,7 +42,7 @@ export interface ReactTestInstance {
findAllByProps(props: { [propName: string]: any }, options?: { deep: boolean }): ReactTestInstance[];
}
export interface ReactTestRenderer {
toJSON(): null | ReactTestRendererJSON;
toJSON(): null | ReactTestRendererJSON | ReactTestRendererJSON[];
toTree(): null | ReactTestRendererTree;
unmount(nextElement?: ReactElement): void;
update(nextElement: ReactElement): void;
Expand Down
11 changes: 10 additions & 1 deletion types/react-test-renderer/react-test-renderer-tests.ts
Expand Up @@ -11,14 +11,22 @@ const renderer = create(React.createElement("div"), {
});

const json = renderer.toJSON();
if (json) {
if (json && !Array.isArray(json)) {
json.type = "t";
json.props = {
prop1: "p",
};
json.children = [json];
}

if (json && Array.isArray(json)) {
json[json.length - 1].type = "t";
json[json.length - 1].props = {
prop1: "p",
};
json[json.length - 1].children = [json[json.length - 1]];
}

const tree = renderer.toTree();
if (tree) {
tree.type = "t";
Expand All @@ -27,6 +35,7 @@ if (tree) {
};
tree.children = [tree];
tree.rendered = tree;
tree.rendered = [tree];
tree.nodeType = "component";
tree.nodeType = "host";
}
Expand Down

0 comments on commit 68c3aea

Please sign in to comment.