@testing-library/react-native 9.0.0 → 10.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.
Files changed (121) hide show
  1. package/README.md +2 -2
  2. package/build/act.d.ts +3 -0
  3. package/build/act.js +2 -1
  4. package/build/act.js.map +1 -0
  5. package/build/cleanup.d.ts +5 -0
  6. package/build/cleanup.js +3 -2
  7. package/build/cleanup.js.map +1 -0
  8. package/build/fireEvent.d.ts +8 -0
  9. package/build/fireEvent.js +2 -1
  10. package/build/fireEvent.js.map +1 -0
  11. package/build/flushMicroTasks.d.ts +5 -0
  12. package/build/flushMicroTasks.js +2 -12
  13. package/build/flushMicroTasks.js.map +1 -0
  14. package/build/helpers/debugDeep.d.ts +5 -0
  15. package/build/helpers/debugDeep.js +4 -1
  16. package/build/helpers/debugDeep.js.map +1 -0
  17. package/build/helpers/debugShallow.d.ts +6 -0
  18. package/build/helpers/debugShallow.js +4 -7
  19. package/build/helpers/debugShallow.js.map +1 -0
  20. package/build/helpers/errors.d.ts +10 -0
  21. package/build/helpers/errors.js +29 -9
  22. package/build/helpers/errors.js.map +1 -0
  23. package/build/helpers/filterNodeByType.d.ts +3 -0
  24. package/build/helpers/filterNodeByType.js +2 -1
  25. package/build/helpers/filterNodeByType.js.map +1 -0
  26. package/build/helpers/format.d.ts +3 -0
  27. package/build/helpers/format.js +4 -3
  28. package/build/helpers/format.js.map +1 -0
  29. package/build/helpers/timers.d.ts +6 -0
  30. package/build/helpers/timers.js +9 -6
  31. package/build/helpers/timers.js.map +1 -0
  32. package/build/index.d.ts +1 -0
  33. package/build/index.flow.js +394 -0
  34. package/build/index.js +2 -1
  35. package/build/index.js.map +1 -0
  36. package/build/matches.d.ts +9 -0
  37. package/build/matches.js +3 -2
  38. package/build/matches.js.map +1 -0
  39. package/build/{pure.js.flow → pure.d.ts} +4 -8
  40. package/build/pure.js +14 -31
  41. package/build/pure.js.map +1 -0
  42. package/build/queries/a11yAPI.d.ts +66 -0
  43. package/build/{helpers → queries}/a11yAPI.js +16 -15
  44. package/build/queries/a11yAPI.js.map +1 -0
  45. package/build/queries/displayValue.d.ts +13 -0
  46. package/build/{helpers/byDisplayValue.js → queries/displayValue.js} +23 -17
  47. package/build/queries/displayValue.js.map +1 -0
  48. package/build/queries/makeA11yQuery.d.ts +13 -0
  49. package/build/{helpers → queries}/makeA11yQuery.js +3 -2
  50. package/build/queries/makeA11yQuery.js.map +1 -0
  51. package/build/queries/makeQueries.d.ts +19 -0
  52. package/build/{helpers → queries}/makeQueries.js +23 -19
  53. package/build/queries/makeQueries.js.map +1 -0
  54. package/build/queries/placeholderText.d.ts +13 -0
  55. package/build/{helpers/byPlaceholderText.js → queries/placeholderText.js} +23 -17
  56. package/build/queries/placeholderText.js.map +1 -0
  57. package/build/queries/testId.d.ts +13 -0
  58. package/build/{helpers/byTestId.js → queries/testId.js} +19 -13
  59. package/build/queries/testId.js.map +1 -0
  60. package/build/queries/text.d.ts +17 -0
  61. package/build/{helpers/byText.js → queries/text.js} +31 -23
  62. package/build/queries/text.js.map +1 -0
  63. package/build/queries/unsafeProps.d.ts +16 -0
  64. package/build/queries/unsafeProps.js +58 -0
  65. package/build/queries/unsafeProps.js.map +1 -0
  66. package/build/queries/unsafeType.d.ts +9 -0
  67. package/build/queries/unsafeType.js +54 -0
  68. package/build/queries/unsafeType.js.map +1 -0
  69. package/build/render.d.ts +135 -0
  70. package/build/render.js +16 -21
  71. package/build/render.js.map +1 -0
  72. package/build/renderHook.d.ts +17 -0
  73. package/build/renderHook.js +57 -0
  74. package/build/renderHook.js.map +1 -0
  75. package/build/shallow.d.ts +8 -0
  76. package/build/shallow.js +3 -9
  77. package/build/shallow.js.map +1 -0
  78. package/build/waitFor.d.ts +8 -0
  79. package/build/waitFor.js +32 -23
  80. package/build/waitFor.js.map +1 -0
  81. package/build/waitForElementToBeRemoved.d.ts +2 -0
  82. package/build/waitForElementToBeRemoved.js +2 -1
  83. package/build/waitForElementToBeRemoved.js.map +1 -0
  84. package/build/within.d.ts +117 -0
  85. package/build/within.js +19 -9
  86. package/build/within.js.map +1 -0
  87. package/package.json +24 -14
  88. package/typings/index.flow.js +394 -0
  89. package/build/act.js.flow +0 -9
  90. package/build/cleanup.js.flow +0 -13
  91. package/build/fireEvent.js.flow +0 -127
  92. package/build/flushMicroTasks.js.flow +0 -23
  93. package/build/helpers/a11yAPI.js.flow +0 -241
  94. package/build/helpers/byDisplayValue.js.flow +0 -66
  95. package/build/helpers/byPlaceholderText.js.flow +0 -62
  96. package/build/helpers/byTestId.js.flow +0 -50
  97. package/build/helpers/byText.js.flow +0 -104
  98. package/build/helpers/debugDeep.js.flow +0 -16
  99. package/build/helpers/debugShallow.js.flow +0 -20
  100. package/build/helpers/errors.js.flow +0 -82
  101. package/build/helpers/filterNodeByType.js.flow +0 -1
  102. package/build/helpers/findByAPI.js +0 -32
  103. package/build/helpers/findByAPI.js.flow +0 -76
  104. package/build/helpers/format.js.flow +0 -10
  105. package/build/helpers/getByAPI.js +0 -98
  106. package/build/helpers/getByAPI.js.flow +0 -157
  107. package/build/helpers/makeA11yQuery.js.flow +0 -98
  108. package/build/helpers/makeQueries.js.flow +0 -165
  109. package/build/helpers/queryByAPI.js +0 -92
  110. package/build/helpers/queryByAPI.js.flow +0 -166
  111. package/build/helpers/timers.js.flow +0 -88
  112. package/build/index.js.flow +0 -18
  113. package/build/matches.js.flow +0 -41
  114. package/build/render.js.flow +0 -109
  115. package/build/shallow.js.flow +0 -26
  116. package/build/types.flow.js +0 -1
  117. package/build/types.flow.js.flow +0 -59
  118. package/build/waitFor.js.flow +0 -221
  119. package/build/waitForElementToBeRemoved.js.flow +0 -42
  120. package/build/within.js.flow +0 -18
  121. package/typings/index.d.ts +0 -432
@@ -0,0 +1,394 @@
1
+ // @flow
2
+ import * as React from 'react';
3
+
4
+ type GetReturn = ReactTestInstance;
5
+ type GetAllReturn = Array<ReactTestInstance>;
6
+ type QueryReturn = ReactTestInstance | null;
7
+ type QueryAllReturn = Array<ReactTestInstance> | [];
8
+ type FindReturn = Promise<ReactTestInstance>;
9
+ type FindAllReturn = Promise<ReactTestInstance[]>;
10
+
11
+ type TextMatch = string | RegExp;
12
+
13
+ declare type NormalizerFn = (textToNormalize: string) => string;
14
+ declare type NormalizerConfig = {
15
+ trim?: boolean,
16
+ collapseWhitespace?: boolean,
17
+ };
18
+ declare type TextMatchOptions = {
19
+ exact?: boolean,
20
+ normalizer?: NormalizerFn,
21
+ };
22
+ declare type A11yRole =
23
+ | 'none'
24
+ | 'button'
25
+ | 'link'
26
+ | 'search'
27
+ | 'image'
28
+ | 'keyboardkey'
29
+ | 'text'
30
+ | 'adjustable'
31
+ | 'imagebutton'
32
+ | 'header'
33
+ | 'summary'
34
+ | 'alert'
35
+ | 'checkbox'
36
+ | 'combobox'
37
+ | 'menu'
38
+ | 'menubar'
39
+ | 'menuitem'
40
+ | 'progressbar'
41
+ | 'radio'
42
+ | 'radiogroup'
43
+ | 'scrollbar'
44
+ | 'spinbutton'
45
+ | 'switch'
46
+ | 'tab'
47
+ | 'tablist'
48
+ | 'timer'
49
+ | 'toolbar';
50
+
51
+ declare type A11yState = {|
52
+ disabled?: boolean,
53
+ selected?: boolean,
54
+ checked?: boolean | 'mixed',
55
+ busy?: boolean,
56
+ expanded?: boolean,
57
+ |};
58
+
59
+ declare type A11yStates =
60
+ | 'disabled'
61
+ | 'selected'
62
+ | 'checked'
63
+ | 'unchecked'
64
+ | 'busy'
65
+ | 'expanded'
66
+ | 'collapsed'
67
+ | 'hasPopup';
68
+
69
+ declare type A11yValue = {
70
+ min?: number,
71
+ max?: number,
72
+ now?: number,
73
+ text?: string,
74
+ };
75
+
76
+ type WaitForOptions = {
77
+ timeout?: number,
78
+ interval?: number,
79
+ onTimeout?: (error: mixed) => Error,
80
+ };
81
+ type WaitForFunction = <T = any>(
82
+ expectation: () => T,
83
+ options?: WaitForOptions
84
+ ) => Promise<T>;
85
+
86
+ interface ByTextQueries {
87
+ getByText: (text: TextMatch, options?: TextMatchOptions) => ReactTestInstance;
88
+ getAllByText: (
89
+ text: TextMatch,
90
+ options?: TextMatchOptions
91
+ ) => Array<ReactTestInstance>;
92
+ queryByText: (
93
+ name: TextMatch,
94
+ options?: TextMatchOptions
95
+ ) => ReactTestInstance | null;
96
+ queryAllByText: (
97
+ text: TextMatch,
98
+ options?: TextMatchOptions
99
+ ) => Array<ReactTestInstance> | [];
100
+ findByText: (
101
+ text: TextMatch,
102
+ queryOptions?: TextMatchOptions,
103
+ waitForOptions?: WaitForOptions
104
+ ) => FindReturn;
105
+ findAllByText: (
106
+ text: TextMatch,
107
+ queryOptions?: TextMatchOptions,
108
+ waitForOptions?: WaitForOptions
109
+ ) => FindAllReturn;
110
+ }
111
+
112
+ interface ByTestIdQueries {
113
+ getByTestId: (
114
+ testID: TextMatch,
115
+ options?: TextMatchOptions
116
+ ) => ReactTestInstance;
117
+ getAllByTestId: (
118
+ testID: TextMatch,
119
+ options?: TextMatchOptions
120
+ ) => Array<ReactTestInstance>;
121
+ queryByTestId: (testID: TextMatch) => ReactTestInstance | null;
122
+ queryAllByTestId: (testID: TextMatch) => Array<ReactTestInstance> | [];
123
+ findByTestId: (
124
+ testID: TextMatch,
125
+ queryOptions?: TextMatchOptions,
126
+ waitForOptions?: WaitForOptions
127
+ ) => FindReturn;
128
+ findAllByTestId: (
129
+ testID: TextMatch,
130
+ queryOptions?: TextMatchOptions,
131
+ waitForOptions?: WaitForOptions
132
+ ) => FindAllReturn;
133
+ }
134
+
135
+ interface ByDisplayValueQueries {
136
+ getByDisplayValue: (
137
+ value: TextMatch,
138
+ options?: TextMatchOptions
139
+ ) => ReactTestInstance;
140
+ getAllByDisplayValue: (
141
+ value: TextMatch,
142
+ options?: TextMatchOptions
143
+ ) => Array<ReactTestInstance>;
144
+ queryByDisplayValue: (
145
+ value: TextMatch,
146
+ options?: TextMatchOptions
147
+ ) => ReactTestInstance | null;
148
+ queryAllByDisplayValue: (
149
+ value: TextMatch,
150
+ options?: TextMatchOptions
151
+ ) => Array<ReactTestInstance> | [];
152
+ findByDisplayValue: (
153
+ value: TextMatch,
154
+ queryOptions?: TextMatchOptions,
155
+ waitForOptions?: WaitForOptions
156
+ ) => FindReturn;
157
+ findAllByDisplayValue: (
158
+ value: TextMatch,
159
+ queryOptions?: TextMatchOptions,
160
+ waitForOptions?: WaitForOptions
161
+ ) => FindAllReturn;
162
+ }
163
+
164
+ interface ByPlaceholderTextQueries {
165
+ getByPlaceholderText: (
166
+ placeholder: TextMatch,
167
+ options?: TextMatchOptions
168
+ ) => ReactTestInstance;
169
+ getAllByPlaceholderText: (
170
+ placeholder: TextMatch,
171
+ options?: TextMatchOptions
172
+ ) => Array<ReactTestInstance>;
173
+ queryByPlaceholderText: (
174
+ placeholder: TextMatch,
175
+ options?: TextMatchOptions
176
+ ) => ReactTestInstance | null;
177
+ queryAllByPlaceholderText: (
178
+ placeholder: TextMatch,
179
+ options?: TextMatchOptions
180
+ ) => Array<ReactTestInstance> | [];
181
+ findByPlaceholderText: (
182
+ placeholder: TextMatch,
183
+ queryOptions?: TextMatchOptions,
184
+ waitForOptions?: WaitForOptions
185
+ ) => FindReturn;
186
+ findAllByPlaceholderText: (
187
+ placeholder: TextMatch,
188
+ queryOptions?: TextMatchOptions,
189
+ waitForOptions?: WaitForOptions
190
+ ) => FindAllReturn;
191
+ }
192
+
193
+ interface UnsafeByTypeQueries {
194
+ UNSAFE_getByType: <P>(type: React.ComponentType<P>) => ReactTestInstance;
195
+ UNSAFE_getAllByType: <P>(
196
+ type: React.ComponentType<P>
197
+ ) => Array<ReactTestInstance>;
198
+ UNSAFE_queryByType: <P>(
199
+ type: React.ComponentType<P>
200
+ ) => ReactTestInstance | null;
201
+ UNSAFE_queryAllByType: <P>(
202
+ type: React.ComponentType<P>
203
+ ) => Array<ReactTestInstance> | [];
204
+ }
205
+
206
+ interface UnsafeByPropsQueries {
207
+ UNSAFE_getByProps: (props: { [string]: any }) => ReactTestInstance;
208
+ UNSAFE_getAllByProps: (props: { [string]: any }) => Array<ReactTestInstance>;
209
+ UNSAFE_queryByProps: (props: { [string]: any }) => ReactTestInstance | null;
210
+ UNSAFE_queryAllByProps: (props: { [string]: any }) =>
211
+ | Array<ReactTestInstance>
212
+ | [];
213
+ }
214
+ interface A11yAPI {
215
+ // Label
216
+ getByLabelText: (matcher: TextMatch) => GetReturn;
217
+ getAllByLabelText: (matcher: TextMatch) => GetAllReturn;
218
+ queryByLabelText: (matcher: TextMatch) => QueryReturn;
219
+ queryAllByLabelText: (matcher: TextMatch) => QueryAllReturn;
220
+ findByLabelText: (
221
+ matcher: TextMatch,
222
+ waitForOptions?: WaitForOptions
223
+ ) => FindReturn;
224
+ findAllByLabelText: (
225
+ matcher: TextMatch,
226
+ waitForOptions?: WaitForOptions
227
+ ) => FindAllReturn;
228
+
229
+ // Hint
230
+ getByA11yHint: (matcher: TextMatch) => GetReturn;
231
+ getByHintText: (matcher: TextMatch) => GetReturn;
232
+ getAllByA11yHint: (matcher: TextMatch) => GetAllReturn;
233
+ getAllByHintText: (matcher: TextMatch) => GetAllReturn;
234
+ queryByA11yHint: (matcher: TextMatch) => QueryReturn;
235
+ queryByHintText: (matcher: TextMatch) => QueryReturn;
236
+ queryAllByA11yHint: (matcher: TextMatch) => QueryAllReturn;
237
+ queryAllByHintText: (matcher: TextMatch) => QueryAllReturn;
238
+ findByA11yHint: (
239
+ matcher: TextMatch,
240
+ waitForOptions?: WaitForOptions
241
+ ) => FindReturn;
242
+ findByHintText: (
243
+ matcher: TextMatch,
244
+ waitForOptions?: WaitForOptions
245
+ ) => FindReturn;
246
+ findAllByA11yHint: (
247
+ matcher: TextMatch,
248
+ waitForOptions?: WaitForOptions
249
+ ) => FindAllReturn;
250
+ findAllByHintText: (
251
+ matcher: TextMatch,
252
+ waitForOptions?: WaitForOptions
253
+ ) => FindAllReturn;
254
+
255
+ // Role
256
+ getByRole: (matcher: A11yRole | RegExp) => GetReturn;
257
+ getAllByRole: (matcher: A11yRole | RegExp) => GetAllReturn;
258
+ queryByRole: (matcher: A11yRole | RegExp) => QueryReturn;
259
+ queryAllByRole: (matcher: A11yRole | RegExp) => QueryAllReturn;
260
+ findByRole: (
261
+ matcher: A11yRole | RegExp,
262
+ waitForOptions?: WaitForOptions
263
+ ) => FindReturn;
264
+ findAllByRole: (
265
+ matcher: A11yRole | RegExp,
266
+ waitForOptions?: WaitForOptions
267
+ ) => FindAllReturn;
268
+
269
+ // States
270
+ getByA11yStates: (matcher: A11yStates | Array<A11yStates>) => GetReturn;
271
+ getAllByA11yStates: (matcher: A11yStates | Array<A11yStates>) => GetAllReturn;
272
+ queryByA11yStates: (matcher: A11yStates | Array<A11yStates>) => QueryReturn;
273
+ queryAllByA11yStates: (
274
+ matcher: A11yStates | Array<A11yStates>
275
+ ) => QueryAllReturn;
276
+
277
+ // State
278
+ getByA11yState: (matcher: A11yStates) => GetReturn;
279
+ getAllByA11yState: (matcher: A11yStates) => GetAllReturn;
280
+ queryByA11yState: (matcher: A11yStates) => QueryReturn;
281
+ queryAllByA11yState: (matcher: A11yStates) => QueryAllReturn;
282
+ findByA11yState: (
283
+ matcher: A11yStates,
284
+ waitForOptions?: WaitForOptions
285
+ ) => FindReturn;
286
+ findAllByA11yState: (
287
+ matcher: A11yStates,
288
+ waitForOptions?: WaitForOptions
289
+ ) => FindAllReturn;
290
+
291
+ // Value
292
+ getByA11yValue: (matcher: A11yValue) => GetReturn;
293
+ getAllByA11yValue: (matcher: A11yValue) => GetAllReturn;
294
+ queryByA11yValue: (matcher: A11yValue) => QueryReturn;
295
+ queryAllByA11yValue: (matcher: A11yValue) => QueryAllReturn;
296
+ findByA11yValue: (
297
+ matcher: A11yValue,
298
+ waitForOptions?: WaitForOptions
299
+ ) => FindReturn;
300
+ findAllByA11yValue: (
301
+ matcher: A11yValue,
302
+ waitForOptions?: WaitForOptions
303
+ ) => FindAllReturn;
304
+ }
305
+
306
+ interface Thenable {
307
+ then: (resolve: () => any, reject?: () => any) => any;
308
+ }
309
+
310
+ interface RenderOptions {
311
+ wrapper?: React.ComponentType<any>;
312
+ createNodeMock?: (element: React.Element<any>) => any;
313
+ }
314
+
315
+ type Debug = {
316
+ (message?: string): void,
317
+ shallow: (message?: string) => void,
318
+ };
319
+
320
+ type Queries = ByTextQueries &
321
+ ByTestIdQueries &
322
+ ByDisplayValueQueries &
323
+ ByPlaceholderTextQueries &
324
+ UnsafeByTypeQueries &
325
+ UnsafeByPropsQueries &
326
+ A11yAPI;
327
+
328
+ interface RenderAPI extends Queries {
329
+ update(nextElement: React.Element<any>): void;
330
+ rerender(nextElement: React.Element<any>): void;
331
+ unmount(nextElement?: React.Element<any>): void;
332
+ toJSON(): ReactTestRendererJSON[] | ReactTestRendererJSON | null;
333
+ debug: Debug;
334
+ container: ReactTestInstance;
335
+ }
336
+
337
+ type FireEventFunction = (
338
+ element: ReactTestInstance,
339
+ eventName: string,
340
+ ...data: Array<any>
341
+ ) => any;
342
+
343
+ type FireEventAPI = FireEventFunction & {
344
+ press: (element: ReactTestInstance, ...data: Array<any>) => any,
345
+ changeText: (element: ReactTestInstance, ...data: Array<any>) => any,
346
+ scroll: (element: ReactTestInstance, ...data: Array<any>) => any,
347
+ };
348
+
349
+ type RenderHookResult<Result, Props> = {
350
+ rerender: (props: Props) => void,
351
+ result: { current: Result },
352
+ unmount: () => void,
353
+ };
354
+
355
+ type RenderHookOptions<Props> = {
356
+ initialProps?: Props,
357
+ wrapper?: React.ComponentType<any>,
358
+ };
359
+
360
+ declare module '@testing-library/react-native' {
361
+ declare export var render: (
362
+ component: React.Element<any>,
363
+ options?: RenderOptions
364
+ ) => RenderAPI;
365
+
366
+ declare export var cleanup: () => void;
367
+ declare export var fireEvent: FireEventAPI;
368
+
369
+ declare export var waitFor: WaitForFunction;
370
+
371
+ declare type WaitForElementToBeRemovedFunction = <T = any>(
372
+ expectation: () => T,
373
+ options?: WaitForOptions
374
+ ) => Promise<T>;
375
+
376
+ declare export var waitForElementToBeRemoved: WaitForElementToBeRemovedFunction;
377
+
378
+ declare export var act: (callback: () => void) => Thenable;
379
+ declare export var within: (instance: ReactTestInstance) => Queries;
380
+ declare export var getQueriesForElement: (
381
+ instance: ReactTestInstance
382
+ ) => Queries;
383
+
384
+ declare export var getDefaultNormalizer: (
385
+ normalizerConfig?: NormalizerConfig
386
+ ) => NormalizerFn;
387
+
388
+ declare type RenderHookFunction = <Result, Props>(
389
+ renderCallback: (props: Props) => Result,
390
+ options?: RenderHookOptions<Props>
391
+ ) => RenderHookResult<Result, Props>;
392
+
393
+ declare export var renderHook: RenderHookFunction;
394
+ }
package/build/act.js.flow DELETED
@@ -1,9 +0,0 @@
1
- // @flow
2
- import { act } from 'react-test-renderer';
3
- import type { Thenable } from './types.flow';
4
-
5
- const actMock = (callback: () => void) => {
6
- callback();
7
- };
8
-
9
- export default (act || actMock: (callback: () => void) => Thenable);
@@ -1,13 +0,0 @@
1
- // @flow
2
- let cleanupQueue = new Set();
3
-
4
- export default function cleanup() {
5
- cleanupQueue.forEach((fn) => fn());
6
- cleanupQueue.clear();
7
- }
8
-
9
- export function addToCleanupQueue(
10
- fn: (nextElement?: React$Element<any>) => void
11
- ) {
12
- cleanupQueue.add(fn);
13
- }
@@ -1,127 +0,0 @@
1
- // @flow
2
- import act from './act';
3
-
4
- const isHostElement = (element?: ReactTestInstance) => {
5
- return typeof element?.type === 'string';
6
- };
7
-
8
- const isTextInput = (element?: ReactTestInstance) => {
9
- const { TextInput } = require('react-native');
10
- return element?.type === TextInput;
11
- };
12
-
13
- const isTouchResponder = (element?: ReactTestInstance) => {
14
- if (!isHostElement(element)) return false;
15
-
16
- return !!element?.props.onStartShouldSetResponder || isTextInput(element);
17
- };
18
-
19
- const isPointerEventEnabled = (
20
- element?: ReactTestInstance,
21
- isParent?: boolean
22
- ) => {
23
- const parentCondition = isParent
24
- ? element?.props.pointerEvents === 'box-only'
25
- : element?.props.pointerEvents === 'box-none';
26
-
27
- if (element?.props.pointerEvents === 'none' || parentCondition) {
28
- return false;
29
- }
30
-
31
- if (!element?.parent) return true;
32
-
33
- return isPointerEventEnabled(element.parent, true);
34
- };
35
-
36
- const isEventEnabled = (
37
- element?: ReactTestInstance,
38
- touchResponder?: ReactTestInstance
39
- ) => {
40
- if (isTextInput(element)) return element?.props.editable !== false;
41
- if (!isPointerEventEnabled(element)) return false;
42
-
43
- const touchStart = touchResponder?.props.onStartShouldSetResponder?.();
44
- const touchMove = touchResponder?.props.onMoveShouldSetResponder?.();
45
-
46
- if (touchStart || touchMove) return true;
47
-
48
- return touchStart === undefined && touchMove === undefined;
49
- };
50
-
51
- const findEventHandler = (
52
- element: ReactTestInstance,
53
- eventName: string,
54
- callsite?: any,
55
- nearestTouchResponder?: ReactTestInstance
56
- ) => {
57
- const touchResponder = isTouchResponder(element)
58
- ? element
59
- : nearestTouchResponder;
60
-
61
- const handler = getEventHandler(element, eventName);
62
- if (handler && isEventEnabled(element, touchResponder)) return handler;
63
-
64
- if (element.parent === null || element.parent.parent === null) {
65
- return null;
66
- }
67
-
68
- return findEventHandler(element.parent, eventName, callsite, touchResponder);
69
- };
70
-
71
- const getEventHandler = (element: ReactTestInstance, eventName: string) => {
72
- const eventHandlerName = toEventHandlerName(eventName);
73
- if (typeof element.props[eventHandlerName] === 'function') {
74
- return element.props[eventHandlerName];
75
- }
76
-
77
- if (typeof element.props[eventName] === 'function') {
78
- return element.props[eventName];
79
- }
80
-
81
- return undefined;
82
- };
83
-
84
- const invokeEvent = (
85
- element: ReactTestInstance,
86
- eventName: string,
87
- callsite?: any,
88
- ...data: Array<any>
89
- ) => {
90
- const handler = findEventHandler(element, eventName, callsite);
91
-
92
- if (!handler) {
93
- return;
94
- }
95
-
96
- let returnValue;
97
-
98
- act(() => {
99
- returnValue = handler(...data);
100
- });
101
-
102
- return returnValue;
103
- };
104
-
105
- const toEventHandlerName = (eventName: string) =>
106
- `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;
107
-
108
- const pressHandler = (element: ReactTestInstance, ...data: Array<any>): void =>
109
- invokeEvent(element, 'press', pressHandler, ...data);
110
- const changeTextHandler = (
111
- element: ReactTestInstance,
112
- ...data: Array<any>
113
- ): void => invokeEvent(element, 'changeText', changeTextHandler, ...data);
114
- const scrollHandler = (element: ReactTestInstance, ...data: Array<any>): void =>
115
- invokeEvent(element, 'scroll', scrollHandler, ...data);
116
-
117
- const fireEvent = (
118
- element: ReactTestInstance,
119
- eventName: string,
120
- ...data: Array<any>
121
- ): void => invokeEvent(element, eventName, fireEvent, ...data);
122
-
123
- fireEvent.press = pressHandler;
124
- fireEvent.changeText = changeTextHandler;
125
- fireEvent.scroll = scrollHandler;
126
-
127
- export default fireEvent;
@@ -1,23 +0,0 @@
1
- // @flow
2
- import { printDeprecationWarning } from './helpers/errors';
3
- import { setImmediate } from './helpers/timers';
4
-
5
- type Thenable<T> = { then: (() => T) => mixed };
6
-
7
- /**
8
- * Wait for microtasks queue to flush
9
- */
10
- export default function flushMicrotasksQueue<T>(): Thenable<T> {
11
- printDeprecationWarning('flushMicrotasksQueue');
12
- return flushMicroTasks();
13
- }
14
-
15
- export function flushMicroTasks<T>(): Thenable<T> {
16
- return {
17
- // using "thenable" instead of a Promise, because otherwise it breaks when
18
- // using "modern" fake timers
19
- then(resolve) {
20
- setImmediate(resolve);
21
- },
22
- };
23
- }