Skip to content

Commit 4fb371b

Browse files
yungstersfacebook-github-bot
authored andcommitted
RN: Add react-test-renderer Flow Definition
Summary: Adds the `react-test-renderer` Flow definition (via `flow-typed`) so it can be used from tests with Flow enabled. Changelog: [Internal] Reviewed By: TheSavior Differential Revision: D28922375 fbshipit-source-id: 9b1be69f1b281bb3c248ca272cf2527baf154e2a
1 parent 29bc961 commit 4fb371b

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

.eslintrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
"@react-native/codegen/react-native-modules": 2
2222
}
2323
},
24+
{
25+
"files": [
26+
"flow-typed/**/*.js",
27+
],
28+
"rules": {
29+
quotes: 0
30+
}
31+
},
2432
{
2533
"files": [
2634
"**/__fixtures__/**/*.js",
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// flow-typed signature: 7bac6c05f7415881918d3d510109e739
2+
// flow-typed version: fce74493f0/react-test-renderer_v16.x.x/flow_>=v0.104.x
3+
4+
// Type definitions for react-test-renderer 16.x.x
5+
// Ported from: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-test-renderer
6+
7+
type ReactComponentInstance = React$Component<any>;
8+
9+
type ReactTestRendererJSON = {
10+
type: string,
11+
props: { [propName: string]: any, ... },
12+
children: null | ReactTestRendererJSON[],
13+
...
14+
};
15+
16+
type ReactTestRendererTree = ReactTestRendererJSON & {
17+
nodeType: "component" | "host",
18+
instance: ?ReactComponentInstance,
19+
rendered: null | ReactTestRendererTree,
20+
...
21+
};
22+
23+
type ReactTestInstance = {
24+
instance: ?ReactComponentInstance,
25+
type: string,
26+
props: { [propName: string]: any, ... },
27+
parent: null | ReactTestInstance,
28+
children: Array<ReactTestInstance | string>,
29+
find(predicate: (node: ReactTestInstance) => boolean): ReactTestInstance,
30+
findByType(type: React$ElementType): ReactTestInstance,
31+
findByProps(props: { [propName: string]: any, ... }): ReactTestInstance,
32+
findAll(
33+
predicate: (node: ReactTestInstance) => boolean,
34+
options?: { deep: boolean, ... }
35+
): ReactTestInstance[],
36+
findAllByType(
37+
type: React$ElementType,
38+
options?: { deep: boolean, ... }
39+
): ReactTestInstance[],
40+
findAllByProps(
41+
props: { [propName: string]: any, ... },
42+
options?: { deep: boolean, ... }
43+
): ReactTestInstance[],
44+
...
45+
};
46+
47+
type TestRendererOptions = { createNodeMock(element: React$Element<any>): any, ... };
48+
49+
declare module "react-test-renderer" {
50+
declare export type ReactTestRenderer = {
51+
toJSON(): null | ReactTestRendererJSON,
52+
toTree(): null | ReactTestRendererTree,
53+
unmount(nextElement?: React$Element<any>): void,
54+
update(nextElement: React$Element<any>): void,
55+
getInstance(): ?ReactComponentInstance,
56+
root: ReactTestInstance,
57+
...
58+
};
59+
60+
declare type Thenable = { then(resolve: () => mixed, reject?: () => mixed): mixed, ... };
61+
62+
declare function create(
63+
nextElement: React$Element<any>,
64+
options?: TestRendererOptions
65+
): ReactTestRenderer;
66+
67+
declare function act(callback: () => void | Promise<void>): Thenable;
68+
}
69+
70+
declare module "react-test-renderer/shallow" {
71+
declare export default class ShallowRenderer {
72+
static createRenderer(): ShallowRenderer;
73+
getMountedInstance(): ReactTestInstance;
74+
getRenderOutput<E: React$Element<any>>(): E;
75+
getRenderOutput(): React$Element<any>;
76+
render(element: React$Element<any>, context?: any): void;
77+
unmount(): void;
78+
}
79+
}

0 commit comments

Comments
 (0)