@testing-library/react-native 10.1.0 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/build/fireEvent.js +15 -13
- package/build/fireEvent.js.map +1 -1
- package/build/helpers/errors.js +1 -3
- package/build/helpers/errors.js.map +1 -1
- package/build/helpers/matchers/matchArrayProp.d.ts +8 -0
- package/build/helpers/matchers/matchArrayProp.js +26 -0
- package/build/helpers/matchers/matchArrayProp.js.map +1 -0
- package/build/helpers/matchers/matchObjectProp.d.ts +12 -0
- package/build/helpers/matchers/matchObjectProp.js +27 -0
- package/build/helpers/matchers/matchObjectProp.js.map +1 -0
- package/build/helpers/matchers/matchStringProp.d.ts +9 -0
- package/build/helpers/matchers/matchStringProp.js +26 -0
- package/build/helpers/matchers/matchStringProp.js.map +1 -0
- package/build/helpers/timers.js +12 -2
- package/build/helpers/timers.js.map +1 -1
- package/build/index.flow.js +6 -24
- package/build/matches.js +2 -1
- package/build/matches.js.map +1 -1
- package/build/queries/a11yState.d.ts +18 -0
- package/build/queries/a11yState.js +53 -0
- package/build/queries/a11yState.js.map +1 -0
- package/build/queries/a11yValue.d.ts +24 -0
- package/build/queries/a11yValue.js +53 -0
- package/build/queries/a11yValue.js.map +1 -0
- package/build/queries/hintText.d.ts +24 -0
- package/build/queries/hintText.js +61 -0
- package/build/queries/hintText.js.map +1 -0
- package/build/queries/labelText.d.ts +12 -0
- package/build/queries/labelText.js +39 -0
- package/build/queries/labelText.js.map +1 -0
- package/build/queries/makeQueries.d.ts +6 -6
- package/build/queries/makeQueries.js +4 -36
- package/build/queries/makeQueries.js.map +1 -1
- package/build/queries/role.d.ts +12 -0
- package/build/queries/role.js +39 -0
- package/build/queries/role.js.map +1 -0
- package/build/queries/text.js +1 -3
- package/build/queries/text.js.map +1 -1
- package/build/render.d.ts +106 -64
- package/build/renderHook.js +2 -2
- package/build/renderHook.js.map +1 -1
- package/build/screen.js +24 -12
- package/build/screen.js.map +1 -1
- package/build/waitFor.js +1 -1
- package/build/waitFor.js.map +1 -1
- package/build/within.d.ts +106 -64
- package/build/within.js +16 -4
- package/build/within.js.map +1 -1
- package/package.json +22 -18
- package/typings/index.flow.js +6 -24
- package/build/queries/a11yAPI.d.ts +0 -66
- package/build/queries/a11yAPI.js +0 -94
- package/build/queries/a11yAPI.js.map +0 -1
- package/build/queries/makeA11yQuery.d.ts +0 -13
- package/build/queries/makeA11yQuery.js +0 -80
- package/build/queries/makeA11yQuery.js.map +0 -1
package/build/render.d.ts
CHANGED
|
@@ -16,94 +16,136 @@ export default function render<T>(component: React.ReactElement<T>, { wrapper: W
|
|
|
16
16
|
rerender: (component: React.ReactElement<any, string | React.JSXElementConstructor<any>>) => void;
|
|
17
17
|
toJSON: () => TestRenderer.ReactTestRendererJSON | TestRenderer.ReactTestRendererJSON[] | null;
|
|
18
18
|
debug: DebugFunction;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
findAllByHintText: (a11yHint: import("./matches").TextMatch, waitForOptions?: import("./waitFor").WaitForOptions | undefined) => Promise<TestRenderer.ReactTestInstance[]>;
|
|
37
|
-
getByRole: (role: RegExp | import("react-native").AccessibilityRole) => TestRenderer.ReactTestInstance;
|
|
38
|
-
getAllByRole: (role: RegExp | import("react-native").AccessibilityRole) => TestRenderer.ReactTestInstance[];
|
|
39
|
-
queryByRole: (role: RegExp | import("react-native").AccessibilityRole) => TestRenderer.ReactTestInstance | null;
|
|
40
|
-
queryAllByRole: (role: RegExp | import("react-native").AccessibilityRole) => TestRenderer.ReactTestInstance[];
|
|
41
|
-
findByRole: (role: import("react-native").AccessibilityRole, waitForOptions?: import("./waitFor").WaitForOptions | undefined) => Promise<TestRenderer.ReactTestInstance>;
|
|
42
|
-
findAllByRole: (role: import("react-native").AccessibilityRole, waitForOptions?: import("./waitFor").WaitForOptions | undefined) => Promise<TestRenderer.ReactTestInstance[]>;
|
|
43
|
-
getByA11yStates: (accessibilityStateKey: keyof import("react-native").AccessibilityState | (keyof import("react-native").AccessibilityState)[]) => TestRenderer.ReactTestInstance;
|
|
44
|
-
getAllByA11yStates: (accessibilityStateKey: keyof import("react-native").AccessibilityState | (keyof import("react-native").AccessibilityState)[]) => TestRenderer.ReactTestInstance[];
|
|
45
|
-
queryByA11yStates: (accessibilityStateKey: keyof import("react-native").AccessibilityState | (keyof import("react-native").AccessibilityState)[]) => TestRenderer.ReactTestInstance | null;
|
|
46
|
-
queryAllByA11yStates: (accessibilityStateKey: keyof import("react-native").AccessibilityState | (keyof import("react-native").AccessibilityState)[]) => TestRenderer.ReactTestInstance[];
|
|
47
|
-
findByA11yStates: (accessibilityStateKey: keyof import("react-native").AccessibilityState, waitForOptions?: import("./waitFor").WaitForOptions | undefined) => Promise<TestRenderer.ReactTestInstance>;
|
|
48
|
-
findAllByA11yStates: (accessibilityStateKey: keyof import("react-native").AccessibilityState, waitForOptions?: import("./waitFor").WaitForOptions | undefined) => Promise<TestRenderer.ReactTestInstance[]>;
|
|
49
|
-
getByA11yState: (accessibilityState: import("react-native").AccessibilityState) => TestRenderer.ReactTestInstance;
|
|
50
|
-
getAllByA11yState: (accessibilityState: import("react-native").AccessibilityState) => TestRenderer.ReactTestInstance[];
|
|
51
|
-
queryByA11yState: (accessibilityState: import("react-native").AccessibilityState) => TestRenderer.ReactTestInstance | null;
|
|
52
|
-
queryAllByA11yState: (accessibilityState: import("react-native").AccessibilityState) => TestRenderer.ReactTestInstance[];
|
|
53
|
-
findByA11yState: (accessibilityState: import("react-native").AccessibilityState, waitForOptions?: import("./waitFor").WaitForOptions | undefined) => Promise<TestRenderer.ReactTestInstance>;
|
|
54
|
-
findAllByA11yState: (accessibilityState: import("react-native").AccessibilityState, waitForOptions?: import("./waitFor").WaitForOptions | undefined) => Promise<TestRenderer.ReactTestInstance[]>;
|
|
55
|
-
getByA11yValue: (a11yValue: {
|
|
19
|
+
UNSAFE_getByProps: (props: {
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
}) => TestRenderer.ReactTestInstance;
|
|
22
|
+
UNSAFE_getAllByProps: (props: {
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
}) => TestRenderer.ReactTestInstance[];
|
|
25
|
+
UNSAFE_queryByProps: (props: {
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
}) => TestRenderer.ReactTestInstance | null;
|
|
28
|
+
UNSAFE_queryAllByProps: (props: {
|
|
29
|
+
[key: string]: any;
|
|
30
|
+
}) => TestRenderer.ReactTestInstance[];
|
|
31
|
+
UNSAFE_getByType: <P>(type: React.ComponentType<P>) => TestRenderer.ReactTestInstance;
|
|
32
|
+
UNSAFE_getAllByType: <P_1>(type: React.ComponentType<P_1>) => TestRenderer.ReactTestInstance[];
|
|
33
|
+
UNSAFE_queryByType: <P_2>(type: React.ComponentType<P_2>) => TestRenderer.ReactTestInstance | null;
|
|
34
|
+
UNSAFE_queryAllByType: <P_3>(type: React.ComponentType<P_3>) => TestRenderer.ReactTestInstance[];
|
|
35
|
+
getByA11yValue: import("./queries/makeQueries").GetByQuery<{
|
|
56
36
|
min?: number | undefined;
|
|
57
37
|
max?: number | undefined;
|
|
58
38
|
now?: number | undefined;
|
|
59
39
|
text?: string | undefined;
|
|
60
|
-
}
|
|
61
|
-
getAllByA11yValue: (
|
|
40
|
+
}, void>;
|
|
41
|
+
getAllByA11yValue: import("./queries/makeQueries").GetAllByQuery<{
|
|
62
42
|
min?: number | undefined;
|
|
63
43
|
max?: number | undefined;
|
|
64
44
|
now?: number | undefined;
|
|
65
45
|
text?: string | undefined;
|
|
66
|
-
}
|
|
67
|
-
queryByA11yValue: (
|
|
46
|
+
}, void>;
|
|
47
|
+
queryByA11yValue: import("./queries/makeQueries").QueryByQuery<{
|
|
68
48
|
min?: number | undefined;
|
|
69
49
|
max?: number | undefined;
|
|
70
50
|
now?: number | undefined;
|
|
71
51
|
text?: string | undefined;
|
|
72
|
-
}
|
|
73
|
-
queryAllByA11yValue: (
|
|
52
|
+
}, void>;
|
|
53
|
+
queryAllByA11yValue: import("./queries/makeQueries").QueryAllByQuery<{
|
|
74
54
|
min?: number | undefined;
|
|
75
55
|
max?: number | undefined;
|
|
76
56
|
now?: number | undefined;
|
|
77
57
|
text?: string | undefined;
|
|
78
|
-
}
|
|
79
|
-
findByA11yValue: (
|
|
58
|
+
}, void>;
|
|
59
|
+
findByA11yValue: import("./queries/makeQueries").FindByQuery<{
|
|
80
60
|
min?: number | undefined;
|
|
81
61
|
max?: number | undefined;
|
|
82
62
|
now?: number | undefined;
|
|
83
63
|
text?: string | undefined;
|
|
84
|
-
},
|
|
85
|
-
findAllByA11yValue: (
|
|
64
|
+
}, void>;
|
|
65
|
+
findAllByA11yValue: import("./queries/makeQueries").FindAllByQuery<{
|
|
86
66
|
min?: number | undefined;
|
|
87
67
|
max?: number | undefined;
|
|
88
68
|
now?: number | undefined;
|
|
89
69
|
text?: string | undefined;
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
70
|
+
}, void>;
|
|
71
|
+
getByAccessibilityValue: import("./queries/makeQueries").GetByQuery<{
|
|
72
|
+
min?: number | undefined;
|
|
73
|
+
max?: number | undefined;
|
|
74
|
+
now?: number | undefined;
|
|
75
|
+
text?: string | undefined;
|
|
76
|
+
}, void>;
|
|
77
|
+
getAllByAccessibilityValue: import("./queries/makeQueries").GetAllByQuery<{
|
|
78
|
+
min?: number | undefined;
|
|
79
|
+
max?: number | undefined;
|
|
80
|
+
now?: number | undefined;
|
|
81
|
+
text?: string | undefined;
|
|
82
|
+
}, void>;
|
|
83
|
+
queryByAccessibilityValue: import("./queries/makeQueries").QueryByQuery<{
|
|
84
|
+
min?: number | undefined;
|
|
85
|
+
max?: number | undefined;
|
|
86
|
+
now?: number | undefined;
|
|
87
|
+
text?: string | undefined;
|
|
88
|
+
}, void>;
|
|
89
|
+
queryAllByAccessibilityValue: import("./queries/makeQueries").QueryAllByQuery<{
|
|
90
|
+
min?: number | undefined;
|
|
91
|
+
max?: number | undefined;
|
|
92
|
+
now?: number | undefined;
|
|
93
|
+
text?: string | undefined;
|
|
94
|
+
}, void>;
|
|
95
|
+
findByAccessibilityValue: import("./queries/makeQueries").FindByQuery<{
|
|
96
|
+
min?: number | undefined;
|
|
97
|
+
max?: number | undefined;
|
|
98
|
+
now?: number | undefined;
|
|
99
|
+
text?: string | undefined;
|
|
100
|
+
}, void>;
|
|
101
|
+
findAllByAccessibilityValue: import("./queries/makeQueries").FindAllByQuery<{
|
|
102
|
+
min?: number | undefined;
|
|
103
|
+
max?: number | undefined;
|
|
104
|
+
now?: number | undefined;
|
|
105
|
+
text?: string | undefined;
|
|
106
|
+
}, void>;
|
|
107
|
+
getByA11yState: import("./queries/makeQueries").GetByQuery<import("react-native").AccessibilityState, void>;
|
|
108
|
+
getAllByA11yState: import("./queries/makeQueries").GetAllByQuery<import("react-native").AccessibilityState, void>;
|
|
109
|
+
queryByA11yState: import("./queries/makeQueries").QueryByQuery<import("react-native").AccessibilityState, void>;
|
|
110
|
+
queryAllByA11yState: import("./queries/makeQueries").QueryAllByQuery<import("react-native").AccessibilityState, void>;
|
|
111
|
+
findByA11yState: import("./queries/makeQueries").FindByQuery<import("react-native").AccessibilityState, void>;
|
|
112
|
+
findAllByA11yState: import("./queries/makeQueries").FindAllByQuery<import("react-native").AccessibilityState, void>;
|
|
113
|
+
getByAccessibilityState: import("./queries/makeQueries").GetByQuery<import("react-native").AccessibilityState, void>;
|
|
114
|
+
getAllByAccessibilityState: import("./queries/makeQueries").GetAllByQuery<import("react-native").AccessibilityState, void>;
|
|
115
|
+
queryByAccessibilityState: import("./queries/makeQueries").QueryByQuery<import("react-native").AccessibilityState, void>;
|
|
116
|
+
queryAllByAccessibilityState: import("./queries/makeQueries").QueryAllByQuery<import("react-native").AccessibilityState, void>;
|
|
117
|
+
findByAccessibilityState: import("./queries/makeQueries").FindByQuery<import("react-native").AccessibilityState, void>;
|
|
118
|
+
findAllByAccessibilityState: import("./queries/makeQueries").FindAllByQuery<import("react-native").AccessibilityState, void>;
|
|
119
|
+
getByRole: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch, void>;
|
|
120
|
+
getAllByRole: import("./queries/makeQueries").GetAllByQuery<import("./matches").TextMatch, void>;
|
|
121
|
+
queryByRole: import("./queries/makeQueries").QueryByQuery<import("./matches").TextMatch, void>;
|
|
122
|
+
queryAllByRole: import("./queries/makeQueries").QueryAllByQuery<import("./matches").TextMatch, void>;
|
|
123
|
+
findByRole: import("./queries/makeQueries").FindByQuery<import("./matches").TextMatch, void>;
|
|
124
|
+
findAllByRole: import("./queries/makeQueries").FindAllByQuery<import("./matches").TextMatch, void>;
|
|
125
|
+
getByHintText: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch, void>;
|
|
126
|
+
getAllByHintText: import("./queries/makeQueries").GetAllByQuery<import("./matches").TextMatch, void>;
|
|
127
|
+
queryByHintText: import("./queries/makeQueries").QueryByQuery<import("./matches").TextMatch, void>;
|
|
128
|
+
queryAllByHintText: import("./queries/makeQueries").QueryAllByQuery<import("./matches").TextMatch, void>;
|
|
129
|
+
findByHintText: import("./queries/makeQueries").FindByQuery<import("./matches").TextMatch, void>;
|
|
130
|
+
findAllByHintText: import("./queries/makeQueries").FindAllByQuery<import("./matches").TextMatch, void>;
|
|
131
|
+
getByA11yHint: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch, void>;
|
|
132
|
+
getAllByA11yHint: import("./queries/makeQueries").GetAllByQuery<import("./matches").TextMatch, void>;
|
|
133
|
+
queryByA11yHint: import("./queries/makeQueries").QueryByQuery<import("./matches").TextMatch, void>;
|
|
134
|
+
queryAllByA11yHint: import("./queries/makeQueries").QueryAllByQuery<import("./matches").TextMatch, void>;
|
|
135
|
+
findByA11yHint: import("./queries/makeQueries").FindByQuery<import("./matches").TextMatch, void>;
|
|
136
|
+
findAllByA11yHint: import("./queries/makeQueries").FindAllByQuery<import("./matches").TextMatch, void>;
|
|
137
|
+
getByAccessibilityHint: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch, void>;
|
|
138
|
+
getAllByAccessibilityHint: import("./queries/makeQueries").GetAllByQuery<import("./matches").TextMatch, void>;
|
|
139
|
+
queryByAccessibilityHint: import("./queries/makeQueries").QueryByQuery<import("./matches").TextMatch, void>;
|
|
140
|
+
queryAllByAccessibilityHint: import("./queries/makeQueries").QueryAllByQuery<import("./matches").TextMatch, void>;
|
|
141
|
+
findByAccessibilityHint: import("./queries/makeQueries").FindByQuery<import("./matches").TextMatch, void>;
|
|
142
|
+
findAllByAccessibilityHint: import("./queries/makeQueries").FindAllByQuery<import("./matches").TextMatch, void>;
|
|
143
|
+
getByLabelText: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch, void>;
|
|
144
|
+
getAllByLabelText: import("./queries/makeQueries").GetAllByQuery<import("./matches").TextMatch, void>;
|
|
145
|
+
queryByLabelText: import("./queries/makeQueries").QueryByQuery<import("./matches").TextMatch, void>;
|
|
146
|
+
queryAllByLabelText: import("./queries/makeQueries").QueryAllByQuery<import("./matches").TextMatch, void>;
|
|
147
|
+
findByLabelText: import("./queries/makeQueries").FindByQuery<import("./matches").TextMatch, void>;
|
|
148
|
+
findAllByLabelText: import("./queries/makeQueries").FindAllByQuery<import("./matches").TextMatch, void>;
|
|
107
149
|
getByPlaceholderText: import("./queries/makeQueries").GetByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
|
|
108
150
|
getAllByPlaceholderText: import("./queries/makeQueries").GetAllByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
|
|
109
151
|
queryByPlaceholderText: import("./queries/makeQueries").QueryByQuery<import("./matches").TextMatch, import("./queries/text").TextMatchOptions>;
|
package/build/renderHook.js
CHANGED
|
@@ -12,8 +12,8 @@ var _render = _interopRequireDefault(require("./render"));
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
14
|
function renderHook(renderCallback, options) {
|
|
15
|
-
const initialProps = options
|
|
16
|
-
const wrapper = options
|
|
15
|
+
const initialProps = options?.initialProps;
|
|
16
|
+
const wrapper = options?.wrapper;
|
|
17
17
|
|
|
18
18
|
const result = /*#__PURE__*/_react.default.createRef();
|
|
19
19
|
|
package/build/renderHook.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/renderHook.tsx"],"names":["renderHook","renderCallback","options","initialProps","wrapper","result","React","createRef","TestComponent","renderCallbackProps","renderResult","useEffect","current","rerender","baseRerender","unmount","rerenderCallbackProps"],"mappings":";;;;;;;AAAA;;AAEA;;;;AAeO,SAASA,UAAT,CACLC,cADK,EAELC,OAFK,EAG4B;AACjC,QAAMC,YAAY,GAAGD,
|
|
1
|
+
{"version":3,"sources":["../src/renderHook.tsx"],"names":["renderHook","renderCallback","options","initialProps","wrapper","result","React","createRef","TestComponent","renderCallbackProps","renderResult","useEffect","current","rerender","baseRerender","unmount","rerenderCallbackProps"],"mappings":";;;;;;;AAAA;;AAEA;;;;AAeO,SAASA,UAAT,CACLC,cADK,EAELC,OAFK,EAG4B;AACjC,QAAMC,YAAY,GAAGD,OAAO,EAAEC,YAA9B;AACA,QAAMC,OAAO,GAAGF,OAAO,EAAEE,OAAzB;;AAEA,QAAMC,MAA6C,gBAAGC,eAAMC,SAAN,EAAtD;;AAEA,WAASC,aAAT,CAAuB;AACrBC,IAAAA;AADqB,GAAvB,EAIG;AACD,UAAMC,YAAY,GAAGT,cAAc,CAACQ,mBAAD,CAAnC;;AAEAH,mBAAMK,SAAN,CAAgB,MAAM;AACpBN,MAAAA,MAAM,CAACO,OAAP,GAAiBF,YAAjB;AACD,KAFD;;AAIA,WAAO,IAAP;AACD;;AAED,QAAM;AAAEG,IAAAA,QAAQ,EAAEC,YAAZ;AAA0BC,IAAAA;AAA1B,MAAsC;AAAA;AAC1C;AACA,+BAAC,aAAD;AAAe,IAAA,mBAAmB,EAAEZ;AAApC,IAF0C,EAG1C;AAAEC,IAAAA;AAAF,GAH0C,CAA5C;;AAMA,WAASS,QAAT,CAAkBG,qBAAlB,EAAgD;AAC9C,WAAOF,YAAY,eACjB,6BAAC,aAAD;AAAe,MAAA,mBAAmB,EAAEE;AAApC,MADiB,CAAnB;AAGD,GA9BgC,CAgCjC;;;AACA,SAAO;AAAEX,IAAAA,MAAF;AAAUQ,IAAAA,QAAV;AAAoBE,IAAAA;AAApB,GAAP;AACD","sourcesContent":["import React from 'react';\nimport type { ComponentType } from 'react';\nimport render from './render';\n\ninterface RenderHookResult<Result, Props> {\n rerender: (props: Props) => void;\n result: { current: Result };\n unmount: () => void;\n}\n\ntype RenderHookOptions<Props> = Props extends object | string | number | boolean\n ? {\n initialProps: Props;\n wrapper?: ComponentType<any>;\n }\n : { wrapper?: ComponentType<any>; initialProps?: never } | undefined;\n\nexport function renderHook<Result, Props>(\n renderCallback: (props: Props) => Result,\n options?: RenderHookOptions<Props>\n): RenderHookResult<Result, Props> {\n const initialProps = options?.initialProps;\n const wrapper = options?.wrapper;\n\n const result: React.MutableRefObject<Result | null> = React.createRef();\n\n function TestComponent({\n renderCallbackProps,\n }: {\n renderCallbackProps: Props;\n }) {\n const renderResult = renderCallback(renderCallbackProps);\n\n React.useEffect(() => {\n result.current = renderResult;\n });\n\n return null;\n }\n\n const { rerender: baseRerender, unmount } = render(\n // @ts-expect-error since option can be undefined, initialProps can be undefined when it should'nt\n <TestComponent renderCallbackProps={initialProps} />,\n { wrapper }\n );\n\n function rerender(rerenderCallbackProps: Props) {\n return baseRerender(\n <TestComponent renderCallbackProps={rerenderCallbackProps} />\n );\n }\n\n // @ts-expect-error result is ill typed because ref is initialized to null\n return { result, rerender, unmount };\n}\n"],"file":"renderHook.js"}
|
package/build/screen.js
CHANGED
|
@@ -33,42 +33,54 @@ const defaultScreen = {
|
|
|
33
33
|
queryAllByLabelText: notImplemented,
|
|
34
34
|
findByLabelText: notImplemented,
|
|
35
35
|
findAllByLabelText: notImplemented,
|
|
36
|
-
getByA11yHint: notImplemented,
|
|
37
36
|
getByHintText: notImplemented,
|
|
38
|
-
getAllByA11yHint: notImplemented,
|
|
39
37
|
getAllByHintText: notImplemented,
|
|
40
|
-
queryByA11yHint: notImplemented,
|
|
41
38
|
queryByHintText: notImplemented,
|
|
42
|
-
queryAllByA11yHint: notImplemented,
|
|
43
39
|
queryAllByHintText: notImplemented,
|
|
44
|
-
findByA11yHint: notImplemented,
|
|
45
40
|
findByHintText: notImplemented,
|
|
46
|
-
findAllByA11yHint: notImplemented,
|
|
47
41
|
findAllByHintText: notImplemented,
|
|
42
|
+
getByA11yHint: notImplemented,
|
|
43
|
+
getAllByA11yHint: notImplemented,
|
|
44
|
+
queryByA11yHint: notImplemented,
|
|
45
|
+
queryAllByA11yHint: notImplemented,
|
|
46
|
+
findByA11yHint: notImplemented,
|
|
47
|
+
findAllByA11yHint: notImplemented,
|
|
48
|
+
getByAccessibilityHint: notImplemented,
|
|
49
|
+
getAllByAccessibilityHint: notImplemented,
|
|
50
|
+
queryByAccessibilityHint: notImplemented,
|
|
51
|
+
queryAllByAccessibilityHint: notImplemented,
|
|
52
|
+
findByAccessibilityHint: notImplemented,
|
|
53
|
+
findAllByAccessibilityHint: notImplemented,
|
|
48
54
|
getByRole: notImplemented,
|
|
49
55
|
getAllByRole: notImplemented,
|
|
50
56
|
queryByRole: notImplemented,
|
|
51
57
|
queryAllByRole: notImplemented,
|
|
52
58
|
findByRole: notImplemented,
|
|
53
59
|
findAllByRole: notImplemented,
|
|
54
|
-
getByA11yStates: notImplemented,
|
|
55
|
-
getAllByA11yStates: notImplemented,
|
|
56
|
-
queryByA11yStates: notImplemented,
|
|
57
|
-
queryAllByA11yStates: notImplemented,
|
|
58
|
-
findByA11yStates: notImplemented,
|
|
59
|
-
findAllByA11yStates: notImplemented,
|
|
60
60
|
getByA11yState: notImplemented,
|
|
61
61
|
getAllByA11yState: notImplemented,
|
|
62
62
|
queryByA11yState: notImplemented,
|
|
63
63
|
queryAllByA11yState: notImplemented,
|
|
64
64
|
findByA11yState: notImplemented,
|
|
65
65
|
findAllByA11yState: notImplemented,
|
|
66
|
+
getByAccessibilityState: notImplemented,
|
|
67
|
+
getAllByAccessibilityState: notImplemented,
|
|
68
|
+
queryByAccessibilityState: notImplemented,
|
|
69
|
+
queryAllByAccessibilityState: notImplemented,
|
|
70
|
+
findByAccessibilityState: notImplemented,
|
|
71
|
+
findAllByAccessibilityState: notImplemented,
|
|
66
72
|
getByA11yValue: notImplemented,
|
|
67
73
|
getAllByA11yValue: notImplemented,
|
|
68
74
|
queryByA11yValue: notImplemented,
|
|
69
75
|
queryAllByA11yValue: notImplemented,
|
|
70
76
|
findByA11yValue: notImplemented,
|
|
71
77
|
findAllByA11yValue: notImplemented,
|
|
78
|
+
getByAccessibilityValue: notImplemented,
|
|
79
|
+
getAllByAccessibilityValue: notImplemented,
|
|
80
|
+
queryByAccessibilityValue: notImplemented,
|
|
81
|
+
queryAllByAccessibilityValue: notImplemented,
|
|
82
|
+
findByAccessibilityValue: notImplemented,
|
|
83
|
+
findAllByAccessibilityValue: notImplemented,
|
|
72
84
|
UNSAFE_getByProps: notImplemented,
|
|
73
85
|
UNSAFE_getAllByProps: notImplemented,
|
|
74
86
|
UNSAFE_queryByProps: notImplemented,
|
package/build/screen.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/screen.ts"],"names":["SCREEN_ERROR","notImplemented","Error","notImplementedDebug","shallow","defaultScreen","container","debug","update","unmount","rerender","toJSON","getByLabelText","getAllByLabelText","queryByLabelText","queryAllByLabelText","findByLabelText","findAllByLabelText","
|
|
1
|
+
{"version":3,"sources":["../src/screen.ts"],"names":["SCREEN_ERROR","notImplemented","Error","notImplementedDebug","shallow","defaultScreen","container","debug","update","unmount","rerender","toJSON","getByLabelText","getAllByLabelText","queryByLabelText","queryAllByLabelText","findByLabelText","findAllByLabelText","getByHintText","getAllByHintText","queryByHintText","queryAllByHintText","findByHintText","findAllByHintText","getByA11yHint","getAllByA11yHint","queryByA11yHint","queryAllByA11yHint","findByA11yHint","findAllByA11yHint","getByAccessibilityHint","getAllByAccessibilityHint","queryByAccessibilityHint","queryAllByAccessibilityHint","findByAccessibilityHint","findAllByAccessibilityHint","getByRole","getAllByRole","queryByRole","queryAllByRole","findByRole","findAllByRole","getByA11yState","getAllByA11yState","queryByA11yState","queryAllByA11yState","findByA11yState","findAllByA11yState","getByAccessibilityState","getAllByAccessibilityState","queryByAccessibilityState","queryAllByAccessibilityState","findByAccessibilityState","findAllByAccessibilityState","getByA11yValue","getAllByA11yValue","queryByA11yValue","queryAllByA11yValue","findByA11yValue","findAllByA11yValue","getByAccessibilityValue","getAllByAccessibilityValue","queryByAccessibilityValue","queryAllByAccessibilityValue","findByAccessibilityValue","findAllByAccessibilityValue","UNSAFE_getByProps","UNSAFE_getAllByProps","UNSAFE_queryByProps","UNSAFE_queryAllByProps","UNSAFE_getByType","UNSAFE_getAllByType","UNSAFE_queryByType","UNSAFE_queryAllByType","getByPlaceholderText","getAllByPlaceholderText","queryByPlaceholderText","queryAllByPlaceholderText","findByPlaceholderText","findAllByPlaceholderText","getByDisplayValue","getAllByDisplayValue","queryByDisplayValue","queryAllByDisplayValue","findByDisplayValue","findAllByDisplayValue","getByTestId","getAllByTestId","queryByTestId","queryAllByTestId","findByTestId","findAllByTestId","getByText","getAllByText","queryByText","queryAllByText","findByText","findAllByText","screen","setRenderResult","output","clearRenderResult"],"mappings":";;;;;;;;AAGA,MAAMA,YAAY,GAAG,q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gB,EAAExF,cAtFgB;AAuFlCyF,EAAAA,YAAY,EAAEzF,cAvFoB;AAwFlC0F,EAAAA,eAAe,EAAE1F,cAxFiB;AAyFlC2F,EAAAA,SAAS,EAAE3F,cAzFuB;AA0FlC4F,EAAAA,YAAY,EAAE5F,cA1FoB;AA2FlC6F,EAAAA,WAAW,EAAE7F,cA3FqB;AA4FlC8F,EAAAA,cAAc,EAAE9F,cA5FkB;AA6FlC+F,EAAAA,UAAU,EAAE/F,cA7FsB;AA8FlCgG,EAAAA,aAAa,EAAEhG;AA9FmB,CAApC;AAiGO,IAAIiG,MAAoB,GAAG7F,aAA3B;;;AAEA,SAAS8F,eAAT,CAAyBC,MAAzB,EAA+C;AACpD,mBAAAF,MAAM,GAAGE,MAAT;AACD;;AAEM,SAASC,iBAAT,GAA6B;AAClC,mBAAAH,MAAM,GAAG7F,aAAT;AACD","sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { RenderResult } from './render';\n\nconst SCREEN_ERROR = '`render` method has not been called';\n\nconst notImplemented = () => {\n throw new Error(SCREEN_ERROR);\n};\n\nconst notImplementedDebug = () => {\n throw new Error(SCREEN_ERROR);\n};\nnotImplementedDebug.shallow = notImplemented;\n\nconst defaultScreen: RenderResult = {\n get container(): ReactTestInstance {\n throw new Error(SCREEN_ERROR);\n },\n debug: notImplementedDebug,\n update: notImplemented,\n unmount: notImplemented,\n rerender: notImplemented,\n toJSON: notImplemented,\n getByLabelText: notImplemented,\n getAllByLabelText: notImplemented,\n queryByLabelText: notImplemented,\n queryAllByLabelText: notImplemented,\n findByLabelText: notImplemented,\n findAllByLabelText: notImplemented,\n getByHintText: notImplemented,\n getAllByHintText: notImplemented,\n queryByHintText: notImplemented,\n queryAllByHintText: notImplemented,\n findByHintText: notImplemented,\n findAllByHintText: notImplemented,\n getByA11yHint: notImplemented,\n getAllByA11yHint: notImplemented,\n queryByA11yHint: notImplemented,\n queryAllByA11yHint: notImplemented,\n findByA11yHint: notImplemented,\n findAllByA11yHint: notImplemented,\n getByAccessibilityHint: notImplemented,\n getAllByAccessibilityHint: notImplemented,\n queryByAccessibilityHint: notImplemented,\n queryAllByAccessibilityHint: notImplemented,\n findByAccessibilityHint: notImplemented,\n findAllByAccessibilityHint: notImplemented,\n getByRole: notImplemented,\n getAllByRole: notImplemented,\n queryByRole: notImplemented,\n queryAllByRole: notImplemented,\n findByRole: notImplemented,\n findAllByRole: notImplemented,\n getByA11yState: notImplemented,\n getAllByA11yState: notImplemented,\n queryByA11yState: notImplemented,\n queryAllByA11yState: notImplemented,\n findByA11yState: notImplemented,\n findAllByA11yState: notImplemented,\n getByAccessibilityState: notImplemented,\n getAllByAccessibilityState: notImplemented,\n queryByAccessibilityState: notImplemented,\n queryAllByAccessibilityState: notImplemented,\n findByAccessibilityState: notImplemented,\n findAllByAccessibilityState: notImplemented,\n getByA11yValue: notImplemented,\n getAllByA11yValue: notImplemented,\n queryByA11yValue: notImplemented,\n queryAllByA11yValue: notImplemented,\n findByA11yValue: notImplemented,\n findAllByA11yValue: notImplemented,\n getByAccessibilityValue: notImplemented,\n getAllByAccessibilityValue: notImplemented,\n queryByAccessibilityValue: notImplemented,\n queryAllByAccessibilityValue: notImplemented,\n findByAccessibilityValue: notImplemented,\n findAllByAccessibilityValue: notImplemented,\n UNSAFE_getByProps: notImplemented,\n UNSAFE_getAllByProps: notImplemented,\n UNSAFE_queryByProps: notImplemented,\n UNSAFE_queryAllByProps: notImplemented,\n UNSAFE_getByType: notImplemented,\n UNSAFE_getAllByType: notImplemented,\n UNSAFE_queryByType: notImplemented,\n UNSAFE_queryAllByType: notImplemented,\n getByPlaceholderText: notImplemented,\n getAllByPlaceholderText: notImplemented,\n queryByPlaceholderText: notImplemented,\n queryAllByPlaceholderText: notImplemented,\n findByPlaceholderText: notImplemented,\n findAllByPlaceholderText: notImplemented,\n getByDisplayValue: notImplemented,\n getAllByDisplayValue: notImplemented,\n queryByDisplayValue: notImplemented,\n queryAllByDisplayValue: notImplemented,\n findByDisplayValue: notImplemented,\n findAllByDisplayValue: notImplemented,\n getByTestId: notImplemented,\n getAllByTestId: notImplemented,\n queryByTestId: notImplemented,\n queryAllByTestId: notImplemented,\n findByTestId: notImplemented,\n findAllByTestId: notImplemented,\n getByText: notImplemented,\n getAllByText: notImplemented,\n queryByText: notImplemented,\n queryAllByText: notImplemented,\n findByText: notImplemented,\n findAllByText: notImplemented,\n};\n\nexport let screen: RenderResult = defaultScreen;\n\nexport function setRenderResult(output: RenderResult) {\n screen = output;\n}\n\nexport function clearRenderResult() {\n screen = defaultScreen;\n}\n"],"file":"screen.js"}
|
package/build/waitFor.js
CHANGED
|
@@ -134,7 +134,7 @@ function waitForInternal(expectation, {
|
|
|
134
134
|
const result = expectation(); // @ts-ignore result can be a promise
|
|
135
135
|
// eslint-disable-next-line promise/prefer-await-to-then
|
|
136
136
|
|
|
137
|
-
if (typeof
|
|
137
|
+
if (typeof result?.then === 'function') {
|
|
138
138
|
const promiseResult = result;
|
|
139
139
|
promiseStatus = 'pending'; // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then
|
|
140
140
|
|
package/build/waitFor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/waitFor.ts"],"names":["DEFAULT_TIMEOUT","DEFAULT_INTERVAL","checkReactVersionAtLeast","major","minor","React","version","undefined","actualMajor","actualMinor","split","map","Number","waitForInternal","expectation","timeout","interval","stackTraceError","onTimeout","TypeError","Promise","resolve","reject","lastError","intervalId","finished","promiseStatus","overallTimeoutTimer","handleTimeout","usingFakeTimers","checkExpectation","fakeTimeRemaining","error","Error","jest","advanceTimersByTime","setInterval","checkRealTimersCallback","onDone","done","clearInterval","type","result","then","promiseResult","resolvedValue","rejectedValue","waitFor","options","ErrorWithStack","optionsWithStackTrace"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAJA;AAWA,MAAMA,eAAe,GAAG,IAAxB;AACA,MAAMC,gBAAgB,GAAG,EAAzB;;AA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AA;AAAjB,OAAD,CAAN;AACD;AACF,GA/IM,CAAP;AAgJD;;AAEc,eAAee,OAAf,CACbjC,WADa,EAEbkC,OAFa,EAGD;AACZ;AACA,QAAM/B,eAAe,GAAG,IAAIgC,sBAAJ,CAAmB,mBAAnB,EAAwCF,OAAxC,CAAxB;AACA,QAAMG,qBAAqB,GAAG;AAAEjC,IAAAA,eAAF;AAAmB,OAAG+B;AAAtB,GAA9B;;AAEA,MAAI,CAAC9C,wBAAwB,CAAC,EAAD,EAAK,CAAL,CAA7B,EAAsC;AACpC,WAAOW,eAAe,CAACC,WAAD,EAAcoC,qBAAd,CAAtB;AACD;;AAED,MAAIR,MAAJ;AAEA,QAAM,kBAAI,YAAY;AACpBA,IAAAA,MAAM,GAAG,MAAM7B,eAAe,CAACC,WAAD,EAAcoC,qBAAd,CAA9B;AACD,GAFK,CAAN,CAXY,CAeZ;;AACA,SAAOR,MAAP;AACD","sourcesContent":["/* globals jest */\nimport * as React from 'react';\nimport act from './act';\nimport { ErrorWithStack, copyStackTrace } from './helpers/errors';\nimport {\n setTimeout,\n clearTimeout,\n setImmediate,\n jestFakeTimersAreEnabled,\n} from './helpers/timers';\n\nconst DEFAULT_TIMEOUT = 1000;\nconst DEFAULT_INTERVAL = 50;\n\nfunction checkReactVersionAtLeast(major: number, minor: number): boolean {\n if (React.version === undefined) return false;\n const [actualMajor, actualMinor] = React.version.split('.').map(Number);\n\n return actualMajor > major || (actualMajor === major && actualMinor >= minor);\n}\n\nexport type WaitForOptions = {\n timeout?: number;\n interval?: number;\n stackTraceError?: ErrorWithStack;\n onTimeout?: (error: unknown) => Error;\n};\n\nfunction waitForInternal<T>(\n expectation: () => T,\n {\n timeout = DEFAULT_TIMEOUT,\n interval = DEFAULT_INTERVAL,\n stackTraceError,\n onTimeout,\n }: WaitForOptions\n): Promise<T> {\n if (typeof expectation !== 'function') {\n throw new TypeError('Received `expectation` arg must be a function');\n }\n\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n let lastError: unknown, intervalId: ReturnType<typeof setTimeout>;\n let finished = false;\n let promiseStatus = 'idle';\n\n const overallTimeoutTimer = setTimeout(handleTimeout, timeout);\n\n const usingFakeTimers = jestFakeTimersAreEnabled();\n\n if (usingFakeTimers) {\n checkExpectation();\n // this is a dangerous rule to disable because it could lead to an\n // infinite loop. However, eslint isn't smart enough to know that we're\n // setting finished inside `onDone` which will be called when we're done\n // waiting or when we've timed out.\n // eslint-disable-next-line no-unmodified-loop-condition\n let fakeTimeRemaining = timeout;\n while (!finished) {\n if (!jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using fake timers to real timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to real timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n reject(error);\n return;\n }\n\n // when fake timers are used we want to simulate the interval time passing\n if (fakeTimeRemaining <= 0) {\n return;\n } else {\n fakeTimeRemaining -= interval;\n }\n\n // we *could* (maybe should?) use `advanceTimersToNextTimer` but it's\n // possible that could make this loop go on forever if someone is using\n // third party code that's setting up recursive timers so rapidly that\n // the user's timer's don't get a chance to resolve. So we'll advance\n // by an interval instead. (We have a test for this case).\n jest.advanceTimersByTime(interval);\n\n // It's really important that checkExpectation is run *before* we flush\n // in-flight promises. To be honest, I'm not sure why, and I can't quite\n // think of a way to reproduce the problem in a test, but I spent\n // an entire day banging my head against a wall on this.\n checkExpectation();\n\n // In this rare case, we *need* to wait for in-flight promises\n // to resolve before continuing. We don't need to take advantage\n // of parallelization so we're fine.\n // https://stackoverflow.com/a/59243586/971592\n // eslint-disable-next-line no-await-in-loop\n await new Promise((resolve) => setImmediate(resolve));\n }\n } else {\n intervalId = setInterval(checkRealTimersCallback, interval);\n checkExpectation();\n }\n\n function onDone(\n done: { type: 'result'; result: T } | { type: 'error'; error: unknown }\n ) {\n finished = true;\n clearTimeout(overallTimeoutTimer);\n\n if (!usingFakeTimers) {\n clearInterval(intervalId);\n }\n\n if (done.type === 'error') {\n reject(done.error);\n } else {\n resolve(done.result);\n }\n }\n\n function checkRealTimersCallback() {\n if (jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using real timers to fake timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to fake timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n return reject(error);\n } else {\n return checkExpectation();\n }\n }\n\n function checkExpectation() {\n if (promiseStatus === 'pending') return;\n try {\n const result = expectation();\n\n // @ts-ignore result can be a promise\n // eslint-disable-next-line promise/prefer-await-to-then\n if (typeof result?.then === 'function') {\n const promiseResult: Promise<T> = result as any;\n promiseStatus = 'pending';\n // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then\n promiseResult.then(\n (resolvedValue) => {\n promiseStatus = 'resolved';\n onDone({ type: 'result', result: resolvedValue });\n return;\n },\n (rejectedValue) => {\n promiseStatus = 'rejected';\n lastError = rejectedValue;\n return;\n }\n );\n } else {\n onDone({ type: 'result', result: result });\n }\n // If `callback` throws, wait for the next mutation, interval, or timeout.\n } catch (error) {\n // Save the most recent callback error to reject the promise with it in the event of a timeout\n lastError = error;\n }\n }\n\n function handleTimeout() {\n let error;\n if (lastError) {\n error = lastError;\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n } else {\n error = new Error('Timed out in waitFor.');\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n }\n if (typeof onTimeout === 'function') {\n onTimeout(error);\n }\n onDone({ type: 'error', error });\n }\n });\n}\n\nexport default async function waitFor<T>(\n expectation: () => T,\n options?: WaitForOptions\n): Promise<T> {\n // Being able to display a useful stack trace requires generating it before doing anything async\n const stackTraceError = new ErrorWithStack('STACK_TRACE_ERROR', waitFor);\n const optionsWithStackTrace = { stackTraceError, ...options };\n\n if (!checkReactVersionAtLeast(16, 9)) {\n return waitForInternal(expectation, optionsWithStackTrace);\n }\n\n let result: T;\n\n await act(async () => {\n result = await waitForInternal(expectation, optionsWithStackTrace);\n });\n\n // Either we have result or `waitFor` threw error\n return result!;\n}\n"],"file":"waitFor.js"}
|
|
1
|
+
{"version":3,"sources":["../src/waitFor.ts"],"names":["DEFAULT_TIMEOUT","DEFAULT_INTERVAL","checkReactVersionAtLeast","major","minor","React","version","undefined","actualMajor","actualMinor","split","map","Number","waitForInternal","expectation","timeout","interval","stackTraceError","onTimeout","TypeError","Promise","resolve","reject","lastError","intervalId","finished","promiseStatus","overallTimeoutTimer","handleTimeout","usingFakeTimers","checkExpectation","fakeTimeRemaining","error","Error","jest","advanceTimersByTime","setInterval","checkRealTimersCallback","onDone","done","clearInterval","type","result","then","promiseResult","resolvedValue","rejectedValue","waitFor","options","ErrorWithStack","optionsWithStackTrace"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAJA;AAWA,MAAMA,eAAe,GAAG,IAAxB;AACA,MAAMC,gBAAgB,GAAG,EAAzB;;AAEA,SAASC,wBAAT,CAAkCC,KAAlC,EAAiDC,KAAjD,EAAyE;AACvE,MAAIC,KAAK,CAACC,OAAN,KAAkBC,SAAtB,EAAiC,OAAO,KAAP;AACjC,QAAM,CAACC,WAAD,EAAcC,WAAd,IAA6BJ,KAAK,CAACC,OAAN,CAAcI,KAAd,CAAoB,GAApB,EAAyBC,GAAzB,CAA6BC,MAA7B,CAAnC;AAEA,SAAOJ,WAAW,GAAGL,KAAd,IAAwBK,WAAW,KAAKL,KAAhB,IAAyBM,WAAW,IAAIL,KAAvE;AACD;;AASD,SAASS,eAAT,CACEC,WADF,EAEE;AACEC,EAAAA,OAAO,GAAGf,eADZ;AAEEgB,EAAAA,QAAQ,GAAGf,gBAFb;AAGEgB,EAAAA,eAHF;AAIEC,EAAAA;AAJF,CAFF,EAQc;AACZ,MAAI,OAAOJ,WAAP,KAAuB,UAA3B,EAAuC;AACrC,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est */\nimport * as React from 'react';\nimport act from './act';\nimport { ErrorWithStack, copyStackTrace } from './helpers/errors';\nimport {\n setTimeout,\n clearTimeout,\n setImmediate,\n jestFakeTimersAreEnabled,\n} from './helpers/timers';\n\nconst DEFAULT_TIMEOUT = 1000;\nconst DEFAULT_INTERVAL = 50;\n\nfunction checkReactVersionAtLeast(major: number, minor: number): boolean {\n if (React.version === undefined) return false;\n const [actualMajor, actualMinor] = React.version.split('.').map(Number);\n\n return actualMajor > major || (actualMajor === major && actualMinor >= minor);\n}\n\nexport type WaitForOptions = {\n timeout?: number;\n interval?: number;\n stackTraceError?: ErrorWithStack;\n onTimeout?: (error: unknown) => Error;\n};\n\nfunction waitForInternal<T>(\n expectation: () => T,\n {\n timeout = DEFAULT_TIMEOUT,\n interval = DEFAULT_INTERVAL,\n stackTraceError,\n onTimeout,\n }: WaitForOptions\n): Promise<T> {\n if (typeof expectation !== 'function') {\n throw new TypeError('Received `expectation` arg must be a function');\n }\n\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n let lastError: unknown, intervalId: ReturnType<typeof setTimeout>;\n let finished = false;\n let promiseStatus = 'idle';\n\n const overallTimeoutTimer = setTimeout(handleTimeout, timeout);\n\n const usingFakeTimers = jestFakeTimersAreEnabled();\n\n if (usingFakeTimers) {\n checkExpectation();\n // this is a dangerous rule to disable because it could lead to an\n // infinite loop. However, eslint isn't smart enough to know that we're\n // setting finished inside `onDone` which will be called when we're done\n // waiting or when we've timed out.\n // eslint-disable-next-line no-unmodified-loop-condition\n let fakeTimeRemaining = timeout;\n while (!finished) {\n if (!jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using fake timers to real timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to real timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n reject(error);\n return;\n }\n\n // when fake timers are used we want to simulate the interval time passing\n if (fakeTimeRemaining <= 0) {\n return;\n } else {\n fakeTimeRemaining -= interval;\n }\n\n // we *could* (maybe should?) use `advanceTimersToNextTimer` but it's\n // possible that could make this loop go on forever if someone is using\n // third party code that's setting up recursive timers so rapidly that\n // the user's timer's don't get a chance to resolve. So we'll advance\n // by an interval instead. (We have a test for this case).\n jest.advanceTimersByTime(interval);\n\n // It's really important that checkExpectation is run *before* we flush\n // in-flight promises. To be honest, I'm not sure why, and I can't quite\n // think of a way to reproduce the problem in a test, but I spent\n // an entire day banging my head against a wall on this.\n checkExpectation();\n\n // In this rare case, we *need* to wait for in-flight promises\n // to resolve before continuing. We don't need to take advantage\n // of parallelization so we're fine.\n // https://stackoverflow.com/a/59243586/971592\n // eslint-disable-next-line no-await-in-loop\n await new Promise((resolve) => setImmediate(resolve));\n }\n } else {\n intervalId = setInterval(checkRealTimersCallback, interval);\n checkExpectation();\n }\n\n function onDone(\n done: { type: 'result'; result: T } | { type: 'error'; error: unknown }\n ) {\n finished = true;\n clearTimeout(overallTimeoutTimer);\n\n if (!usingFakeTimers) {\n clearInterval(intervalId);\n }\n\n if (done.type === 'error') {\n reject(done.error);\n } else {\n resolve(done.result);\n }\n }\n\n function checkRealTimersCallback() {\n if (jestFakeTimersAreEnabled()) {\n const error = new Error(\n `Changed from using real timers to fake timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to fake timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`\n );\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n return reject(error);\n } else {\n return checkExpectation();\n }\n }\n\n function checkExpectation() {\n if (promiseStatus === 'pending') return;\n try {\n const result = expectation();\n\n // @ts-ignore result can be a promise\n // eslint-disable-next-line promise/prefer-await-to-then\n if (typeof result?.then === 'function') {\n const promiseResult: Promise<T> = result as any;\n promiseStatus = 'pending';\n // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then\n promiseResult.then(\n (resolvedValue) => {\n promiseStatus = 'resolved';\n onDone({ type: 'result', result: resolvedValue });\n return;\n },\n (rejectedValue) => {\n promiseStatus = 'rejected';\n lastError = rejectedValue;\n return;\n }\n );\n } else {\n onDone({ type: 'result', result: result });\n }\n // If `callback` throws, wait for the next mutation, interval, or timeout.\n } catch (error) {\n // Save the most recent callback error to reject the promise with it in the event of a timeout\n lastError = error;\n }\n }\n\n function handleTimeout() {\n let error;\n if (lastError) {\n error = lastError;\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n } else {\n error = new Error('Timed out in waitFor.');\n if (stackTraceError) {\n copyStackTrace(error, stackTraceError);\n }\n }\n if (typeof onTimeout === 'function') {\n onTimeout(error);\n }\n onDone({ type: 'error', error });\n }\n });\n}\n\nexport default async function waitFor<T>(\n expectation: () => T,\n options?: WaitForOptions\n): Promise<T> {\n // Being able to display a useful stack trace requires generating it before doing anything async\n const stackTraceError = new ErrorWithStack('STACK_TRACE_ERROR', waitFor);\n const optionsWithStackTrace = { stackTraceError, ...options };\n\n if (!checkReactVersionAtLeast(16, 9)) {\n return waitForInternal(expectation, optionsWithStackTrace);\n }\n\n let result: T;\n\n await act(async () => {\n result = await waitForInternal(expectation, optionsWithStackTrace);\n });\n\n // Either we have result or `waitFor` threw error\n return result!;\n}\n"],"file":"waitFor.js"}
|