@testing-library/react-native 9.0.0-alpha.0 → 9.2.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/a11yAPI.d.ts +66 -0
  15. package/build/helpers/a11yAPI.js +16 -15
  16. package/build/helpers/a11yAPI.js.map +1 -0
  17. package/build/helpers/byDisplayValue.d.ts +6 -0
  18. package/build/helpers/byDisplayValue.js +2 -1
  19. package/build/helpers/byDisplayValue.js.map +1 -0
  20. package/build/helpers/byPlaceholderText.d.ts +6 -0
  21. package/build/helpers/byPlaceholderText.js +2 -1
  22. package/build/helpers/byPlaceholderText.js.map +1 -0
  23. package/build/helpers/byTestId.d.ts +6 -0
  24. package/build/helpers/byTestId.js +2 -1
  25. package/build/helpers/byTestId.js.map +1 -0
  26. package/build/helpers/byText.d.ts +10 -0
  27. package/build/helpers/byText.js +8 -5
  28. package/build/helpers/byText.js.map +1 -0
  29. package/build/helpers/debugDeep.d.ts +5 -0
  30. package/build/helpers/debugDeep.js +4 -1
  31. package/build/helpers/debugDeep.js.map +1 -0
  32. package/build/helpers/debugShallow.d.ts +6 -0
  33. package/build/helpers/debugShallow.js +4 -7
  34. package/build/helpers/debugShallow.js.map +1 -0
  35. package/build/helpers/errors.d.ts +10 -0
  36. package/build/helpers/errors.js +29 -9
  37. package/build/helpers/errors.js.map +1 -0
  38. package/build/helpers/filterNodeByType.d.ts +3 -0
  39. package/build/helpers/filterNodeByType.js +2 -1
  40. package/build/helpers/filterNodeByType.js.map +1 -0
  41. package/build/helpers/findByAPI.d.ts +17 -0
  42. package/build/helpers/findByAPI.js +2 -1
  43. package/build/helpers/findByAPI.js.map +1 -0
  44. package/build/helpers/format.d.ts +3 -0
  45. package/build/helpers/format.js +4 -3
  46. package/build/helpers/format.js.map +1 -0
  47. package/build/helpers/getByAPI.d.ts +31 -0
  48. package/build/helpers/getByAPI.js +4 -19
  49. package/build/helpers/getByAPI.js.map +1 -0
  50. package/build/helpers/makeA11yQuery.d.ts +13 -0
  51. package/build/helpers/makeA11yQuery.js +2 -1
  52. package/build/helpers/makeA11yQuery.js.map +1 -0
  53. package/build/helpers/makeQueries.d.ts +20 -0
  54. package/build/helpers/makeQueries.js +6 -3
  55. package/build/helpers/makeQueries.js.map +1 -0
  56. package/build/helpers/queryByAPI.d.ts +39 -0
  57. package/build/helpers/queryByAPI.js +3 -8
  58. package/build/helpers/queryByAPI.js.map +1 -0
  59. package/build/helpers/timers.d.ts +6 -0
  60. package/build/helpers/timers.js +9 -6
  61. package/build/helpers/timers.js.map +1 -0
  62. package/build/index.d.ts +1 -0
  63. package/build/index.flow.js +384 -0
  64. package/build/index.js +2 -1
  65. package/build/index.js.map +1 -0
  66. package/build/matches.d.ts +9 -0
  67. package/build/matches.js +3 -2
  68. package/build/matches.js.map +1 -0
  69. package/build/{pure.js.flow → pure.d.ts} +4 -8
  70. package/build/pure.js +14 -31
  71. package/build/pure.js.map +1 -0
  72. package/build/render.d.ts +145 -0
  73. package/build/render.js +14 -10
  74. package/build/render.js.map +1 -0
  75. package/build/renderHook.d.ts +17 -0
  76. package/build/renderHook.js +57 -0
  77. package/build/renderHook.js.map +1 -0
  78. package/build/shallow.d.ts +8 -0
  79. package/build/shallow.js +3 -9
  80. package/build/shallow.js.map +1 -0
  81. package/build/waitFor.d.ts +8 -0
  82. package/build/waitFor.js +32 -23
  83. package/build/waitFor.js.map +1 -0
  84. package/build/waitForElementToBeRemoved.d.ts +2 -0
  85. package/build/waitForElementToBeRemoved.js +2 -1
  86. package/build/waitForElementToBeRemoved.js.map +1 -0
  87. package/build/within.d.ts +127 -0
  88. package/build/within.js +3 -2
  89. package/build/within.js.map +1 -0
  90. package/package.json +25 -15
  91. package/typings/index.flow.js +384 -0
  92. package/build/act.js.flow +0 -9
  93. package/build/cleanup.js.flow +0 -13
  94. package/build/fireEvent.js.flow +0 -127
  95. package/build/flushMicroTasks.js.flow +0 -23
  96. package/build/helpers/a11yAPI.js.flow +0 -241
  97. package/build/helpers/byDisplayValue.js.flow +0 -66
  98. package/build/helpers/byPlaceholderText.js.flow +0 -62
  99. package/build/helpers/byTestId.js.flow +0 -50
  100. package/build/helpers/byText.js.flow +0 -104
  101. package/build/helpers/debugDeep.js.flow +0 -16
  102. package/build/helpers/debugShallow.js.flow +0 -20
  103. package/build/helpers/errors.js.flow +0 -82
  104. package/build/helpers/filterNodeByType.js.flow +0 -1
  105. package/build/helpers/findByAPI.js.flow +0 -76
  106. package/build/helpers/format.js.flow +0 -10
  107. package/build/helpers/getByAPI.js.flow +0 -157
  108. package/build/helpers/makeA11yQuery.js.flow +0 -98
  109. package/build/helpers/makeQueries.js.flow +0 -165
  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
@@ -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
- }
@@ -1,241 +0,0 @@
1
- // @flow
2
- import type { A11yRole, A11yStates, A11yState, A11yValue } from '../types.flow';
3
- import type { WaitForOptions } from '../waitFor';
4
- import makeA11yQuery from './makeA11yQuery';
5
-
6
- type GetReturn = ReactTestInstance;
7
- type GetAllReturn = Array<ReactTestInstance>;
8
- type QueryReturn = ReactTestInstance | null;
9
- type QueryAllReturn = Array<ReactTestInstance>;
10
- type FindReturn = Promise<GetReturn>;
11
- type FindAllReturn = Promise<GetAllReturn>;
12
-
13
- export type A11yAPI = {|
14
- // Label
15
- getByA11yLabel: (string | RegExp) => GetReturn,
16
- getByLabelText: (string | RegExp) => GetReturn,
17
- getAllByA11yLabel: (string | RegExp) => GetAllReturn,
18
- getAllByLabelText: (string | RegExp) => GetAllReturn,
19
- queryByA11yLabel: (string | RegExp) => QueryReturn,
20
- queryByLabelText: (string | RegExp) => QueryReturn,
21
- queryAllByA11yLabel: (string | RegExp) => QueryAllReturn,
22
- queryAllByLabelText: (string | RegExp) => QueryAllReturn,
23
- findByA11yLabel: (string | RegExp, ?WaitForOptions) => FindReturn,
24
- findByLabelText: (string | RegExp, ?WaitForOptions) => FindReturn,
25
- findAllByA11yLabel: (string | RegExp, ?WaitForOptions) => FindAllReturn,
26
- findAllByLabelText: (string | RegExp, ?WaitForOptions) => FindAllReturn,
27
-
28
- // Hint
29
- getByA11yHint: (string | RegExp) => GetReturn,
30
- getByHintText: (string | RegExp) => GetReturn,
31
- getAllByA11yHint: (string | RegExp) => GetAllReturn,
32
- getAllByHintText: (string | RegExp) => GetAllReturn,
33
- queryByA11yHint: (string | RegExp) => QueryReturn,
34
- queryByHintText: (string | RegExp) => QueryReturn,
35
- queryAllByA11yHint: (string | RegExp) => QueryAllReturn,
36
- queryAllByHintText: (string | RegExp) => QueryAllReturn,
37
- findByA11yHint: (string | RegExp, ?WaitForOptions) => FindReturn,
38
- findByHintText: (string | RegExp, ?WaitForOptions) => FindReturn,
39
- findAllByA11yHint: (string | RegExp, ?WaitForOptions) => FindAllReturn,
40
- findAllByHintText: (string | RegExp, ?WaitForOptions) => FindAllReturn,
41
-
42
- // Role
43
- getByA11yRole: (A11yRole | RegExp) => GetReturn,
44
- getByRole: (A11yRole | RegExp) => GetReturn,
45
- getAllByA11yRole: (A11yRole | RegExp) => GetAllReturn,
46
- getAllByRole: (A11yRole | RegExp) => GetAllReturn,
47
- queryByA11yRole: (A11yRole | RegExp) => QueryReturn,
48
- queryByRole: (A11yRole | RegExp) => QueryReturn,
49
- queryAllByA11yRole: (A11yRole | RegExp) => QueryAllReturn,
50
- queryAllByRole: (A11yRole | RegExp) => QueryAllReturn,
51
- findByA11yRole: (A11yRole, ?WaitForOptions) => FindReturn,
52
- findByRole: (A11yRole, ?WaitForOptions) => FindReturn,
53
- findAllByA11yRole: (A11yRole, ?WaitForOptions) => FindAllReturn,
54
- findAllByRole: (A11yRole, ?WaitForOptions) => FindAllReturn,
55
-
56
- // States
57
- getByA11yStates: (A11yStates | Array<A11yStates>) => GetReturn,
58
- getAllByA11yStates: (A11yStates | Array<A11yStates>) => GetAllReturn,
59
- queryByA11yStates: (A11yStates | Array<A11yStates>) => QueryReturn,
60
- queryAllByA11yStates: (A11yStates | Array<A11yStates>) => QueryAllReturn,
61
- findByA11yStates: (A11yStates, ?WaitForOptions) => FindReturn,
62
- findAllByA11yStates: (A11yStates, ?WaitForOptions) => FindAllReturn,
63
-
64
- // State
65
- getByA11yState: (A11yState) => GetReturn,
66
- getAllByA11yState: (A11yState) => GetAllReturn,
67
- queryByA11yState: (A11yState) => QueryReturn,
68
- queryAllByA11yState: (A11yState) => QueryAllReturn,
69
- findByA11yState: (A11yState, ?WaitForOptions) => FindReturn,
70
- findAllByA11yState: (A11yState, ?WaitForOptions) => FindAllReturn,
71
-
72
- // Value
73
- getByA11yValue: (A11yValue) => GetReturn,
74
- getAllByA11yValue: (A11yValue) => GetAllReturn,
75
- queryByA11yValue: (A11yValue) => QueryReturn,
76
- queryAllByA11yValue: (A11yValue) => QueryAllReturn,
77
- findByA11yValue: (A11yValue, ?WaitForOptions) => FindReturn,
78
- findAllByA11yValue: (A11yValue, ?WaitForOptions) => FindAllReturn,
79
- |};
80
-
81
- export function matchStringValue(
82
- prop?: string,
83
- matcher: string | RegExp
84
- ): boolean {
85
- if (!prop) {
86
- return false;
87
- }
88
-
89
- if (typeof matcher === 'string') {
90
- return prop === matcher;
91
- }
92
-
93
- return Boolean(prop.match(matcher));
94
- }
95
-
96
- export function matchArrayValue(
97
- prop?: Array<string>,
98
- matcher: string | Array<string>
99
- ): boolean {
100
- if (!prop || matcher.length === 0) {
101
- return false;
102
- }
103
-
104
- if (typeof matcher === 'string') {
105
- return prop.includes(matcher);
106
- }
107
-
108
- return !matcher.some((e) => !prop.includes(e));
109
- }
110
-
111
- export function matchObject<T: {}>(prop?: T, matcher: T): boolean {
112
- return prop
113
- ? Object.keys(matcher).length !== 0 &&
114
- Object.keys(prop).length !== 0 &&
115
- !Object.keys(matcher).some((key) => prop[key] !== matcher[key])
116
- : false;
117
- }
118
-
119
- export const a11yAPI = (instance: ReactTestInstance): A11yAPI =>
120
- ({
121
- ...makeA11yQuery(
122
- 'accessibilityLabel',
123
- {
124
- getBy: ['getByA11yLabel', 'getByAccessibilityLabel', 'getByLabelText'],
125
- getAllBy: [
126
- 'getAllByA11yLabel',
127
- 'getAllByAccessibilityLabel',
128
- 'getAllByLabelText',
129
- ],
130
- queryBy: [
131
- 'queryByA11yLabel',
132
- 'queryByAccessibilityLabel',
133
- 'queryByLabelText',
134
- ],
135
- queryAllBy: [
136
- 'queryAllByA11yLabel',
137
- 'queryAllByAccessibilityLabel',
138
- 'queryAllByLabelText',
139
- ],
140
- findBy: [
141
- 'findByA11yLabel',
142
- 'findByAccessibilityLabel',
143
- 'findByLabelText',
144
- ],
145
- findAllBy: [
146
- 'findAllByA11yLabel',
147
- 'findAllByAccessibilityLabel',
148
- 'findAllByLabelText',
149
- ],
150
- },
151
- matchStringValue
152
- )(instance),
153
- ...makeA11yQuery(
154
- 'accessibilityHint',
155
- {
156
- getBy: ['getByA11yHint', 'getByAccessibilityHint', 'getByHintText'],
157
- getAllBy: [
158
- 'getAllByA11yHint',
159
- 'getAllByAccessibilityHint',
160
- 'getAllByHintText',
161
- ],
162
- queryBy: [
163
- 'queryByA11yHint',
164
- 'queryByAccessibilityHint',
165
- 'queryByHintText',
166
- ],
167
- queryAllBy: [
168
- 'queryAllByA11yHint',
169
- 'queryAllByAccessibilityHint',
170
- 'queryAllByHintText',
171
- ],
172
- findBy: ['findByA11yHint', 'findByAccessibilityHint', 'findByHintText'],
173
- findAllBy: [
174
- 'findAllByA11yHint',
175
- 'findAllByAccessibilityHint',
176
- 'findAllByHintText',
177
- ],
178
- },
179
- matchStringValue
180
- )(instance),
181
- ...makeA11yQuery(
182
- 'accessibilityRole',
183
- {
184
- getBy: ['getByA11yRole', 'getByAccessibilityRole', 'getByRole'],
185
- getAllBy: [
186
- 'getAllByA11yRole',
187
- 'getAllByAccessibilityRole',
188
- 'getAllByRole',
189
- ],
190
- queryBy: ['queryByA11yRole', 'queryByAccessibilityRole', 'queryByRole'],
191
- queryAllBy: [
192
- 'queryAllByA11yRole',
193
- 'queryAllByAccessibilityRole',
194
- 'queryAllByRole',
195
- ],
196
- findBy: ['findByA11yRole', 'findByAccessibilityRole', 'findByRole'],
197
- findAllBy: [
198
- 'findAllByA11yRole',
199
- 'findAllByAccessibilityRole',
200
- 'findAllByRole',
201
- ],
202
- },
203
- matchStringValue
204
- )(instance),
205
- ...makeA11yQuery(
206
- 'accessibilityStates',
207
- {
208
- getBy: ['getByA11yStates', 'getByAccessibilityStates'],
209
- getAllBy: ['getAllByA11yStates', 'getAllByAccessibilityStates'],
210
- queryBy: ['queryByA11yStates', 'queryByAccessibilityStates'],
211
- queryAllBy: ['queryAllByA11yStates', 'queryAllByAccessibilityStates'],
212
- findBy: ['findByA11yStates', 'findByAccessibilityStates'],
213
- findAllBy: ['findAllByA11yStates', 'findAllByAccessibilityStates'],
214
- },
215
- matchArrayValue
216
- )(instance),
217
- ...makeA11yQuery(
218
- 'accessibilityState',
219
- {
220
- getBy: ['getByA11yState', 'getByAccessibilityState'],
221
- getAllBy: ['getAllByA11yState', 'getAllByAccessibilityState'],
222
- queryBy: ['queryByA11yState', 'queryByAccessibilityState'],
223
- queryAllBy: ['queryAllByA11yState', 'queryAllByAccessibilityState'],
224
- findBy: ['findByA11yState', 'findByAccessibilityState'],
225
- findAllBy: ['findAllByA11yState', 'findAllByAccessibilityState'],
226
- },
227
- matchObject
228
- )(instance),
229
- ...makeA11yQuery(
230
- 'accessibilityValue',
231
- {
232
- getBy: ['getByA11yValue', 'getByAccessibilityValue'],
233
- getAllBy: ['getAllByA11yValue', 'getAllByAccessibilityValue'],
234
- queryBy: ['queryByA11yValue', 'queryByAccessibilityValue'],
235
- queryAllBy: ['queryAllByA11yValue', 'queryAllByAccessibilityValue'],
236
- findBy: ['findByA11yValue', 'findByAccessibilityValue'],
237
- findAllBy: ['findAllByA11yValue', 'findAllByAccessibilityValue'],
238
- },
239
- matchObject
240
- )(instance),
241
- }: any);
@@ -1,66 +0,0 @@
1
- // @flow
2
- import { matches } from '../matches';
3
- import { makeQueries } from './makeQueries';
4
- import type { Queries } from './makeQueries';
5
- import { filterNodeByType } from './filterNodeByType';
6
- import { createLibraryNotSupportedError } from './errors';
7
- import type { TextMatchOptions } from './byText';
8
-
9
- const getTextInputNodeByDisplayValue = (
10
- node,
11
- value,
12
- options?: TextMatchOptions = {}
13
- ) => {
14
- try {
15
- const { TextInput } = require('react-native');
16
- const { exact, normalizer } = options;
17
- const nodeValue =
18
- node.props.value !== undefined
19
- ? node.props.value
20
- : node.props.defaultValue;
21
- return (
22
- filterNodeByType(node, TextInput) &&
23
- matches(value, nodeValue, normalizer, exact)
24
- );
25
- } catch (error) {
26
- throw createLibraryNotSupportedError(error);
27
- }
28
- };
29
-
30
- const queryAllByDisplayValue = (
31
- instance: ReactTestInstance
32
- ): ((
33
- displayValue: string | RegExp,
34
- queryOptions?: TextMatchOptions
35
- ) => Array<ReactTestInstance>) =>
36
- function queryAllByDisplayValueFn(displayValue, queryOptions) {
37
- return instance.findAll((node) =>
38
- getTextInputNodeByDisplayValue(node, displayValue, queryOptions)
39
- );
40
- };
41
-
42
- const getMultipleError = (displayValue: string | RegExp) =>
43
- `Found multiple elements with display value: ${String(displayValue)} `;
44
- const getMissingError = (displayValue: string | RegExp) =>
45
- `Unable to find an element with displayValue: ${String(displayValue)}`;
46
-
47
- const {
48
- getBy: getByDisplayValue,
49
- getAllBy: getAllByDisplayValue,
50
- queryBy: queryByDisplayValue,
51
- findBy: findByDisplayValue,
52
- findAllBy: findAllByDisplayValue,
53
- }: Queries<string | RegExp> = makeQueries(
54
- queryAllByDisplayValue,
55
- getMissingError,
56
- getMultipleError
57
- );
58
-
59
- export {
60
- findAllByDisplayValue,
61
- findByDisplayValue,
62
- getAllByDisplayValue,
63
- getByDisplayValue,
64
- queryAllByDisplayValue,
65
- queryByDisplayValue,
66
- };
@@ -1,62 +0,0 @@
1
- // @flow
2
- import { matches } from '../matches';
3
- import { makeQueries } from './makeQueries';
4
- import type { Queries } from './makeQueries';
5
- import { filterNodeByType } from './filterNodeByType';
6
- import { createLibraryNotSupportedError } from './errors';
7
- import type { TextMatchOptions } from './byText';
8
-
9
- const getTextInputNodeByPlaceholderText = (
10
- node,
11
- placeholder,
12
- options?: TextMatchOptions = {}
13
- ) => {
14
- try {
15
- const { TextInput } = require('react-native');
16
- const { exact, normalizer } = options;
17
- return (
18
- filterNodeByType(node, TextInput) &&
19
- matches(placeholder, node.props.placeholder, normalizer, exact)
20
- );
21
- } catch (error) {
22
- throw createLibraryNotSupportedError(error);
23
- }
24
- };
25
-
26
- const queryAllByPlaceholderText = (
27
- instance: ReactTestInstance
28
- ): ((
29
- placeholder: string | RegExp,
30
- queryOptions?: TextMatchOptions
31
- ) => Array<ReactTestInstance>) =>
32
- function queryAllByPlaceholderFn(placeholder, queryOptions) {
33
- return instance.findAll((node) =>
34
- getTextInputNodeByPlaceholderText(node, placeholder, queryOptions)
35
- );
36
- };
37
-
38
- const getMultipleError = (placeholder) =>
39
- `Found multiple elements with placeholder: ${String(placeholder)} `;
40
- const getMissingError = (placeholder) =>
41
- `Unable to find an element with placeholder: ${String(placeholder)}`;
42
-
43
- const {
44
- getBy: getByPlaceholderText,
45
- getAllBy: getAllByPlaceholderText,
46
- queryBy: queryByPlaceholderText,
47
- findBy: findByPlaceholderText,
48
- findAllBy: findAllByPlaceholderText,
49
- }: Queries<string | RegExp> = makeQueries(
50
- queryAllByPlaceholderText,
51
- getMissingError,
52
- getMultipleError
53
- );
54
-
55
- export {
56
- findAllByPlaceholderText,
57
- findByPlaceholderText,
58
- getAllByPlaceholderText,
59
- getByPlaceholderText,
60
- queryAllByPlaceholderText,
61
- queryByPlaceholderText,
62
- };
@@ -1,50 +0,0 @@
1
- // @flow
2
- import { matches } from '../matches';
3
- import { makeQueries } from './makeQueries';
4
- import type { Queries } from './makeQueries';
5
- import type { TextMatchOptions } from './byText';
6
-
7
- const getNodeByTestId = (node, testID, options?: TextMatchOptions = {}) => {
8
- const { exact, normalizer } = options;
9
- return matches(testID, node.props.testID, normalizer, exact);
10
- };
11
-
12
- const queryAllByTestId = (
13
- instance: ReactTestInstance
14
- ): ((
15
- testId: string | RegExp,
16
- queryOptions?: TextMatchOptions
17
- ) => Array<ReactTestInstance>) =>
18
- function queryAllByTestIdFn(testId, queryOptions) {
19
- const results = instance
20
- .findAll((node) => getNodeByTestId(node, testId, queryOptions))
21
- .filter((element) => typeof element.type === 'string');
22
-
23
- return results;
24
- };
25
-
26
- const getMultipleError = (testId) =>
27
- `Found multiple elements with testID: ${String(testId)}`;
28
- const getMissingError = (testId) =>
29
- `Unable to find an element with testID: ${String(testId)}`;
30
-
31
- const {
32
- getBy: getByTestId,
33
- getAllBy: getAllByTestId,
34
- queryBy: queryByTestId,
35
- findBy: findByTestId,
36
- findAllBy: findAllByTestId,
37
- }: Queries<string | RegExp> = makeQueries(
38
- queryAllByTestId,
39
- getMissingError,
40
- getMultipleError
41
- );
42
-
43
- export {
44
- findAllByTestId,
45
- findByTestId,
46
- getAllByTestId,
47
- getByTestId,
48
- queryAllByTestId,
49
- queryByTestId,
50
- };
@@ -1,104 +0,0 @@
1
- // @flow
2
- import * as React from 'react';
3
- import { matches } from '../matches';
4
- import type { NormalizerFn } from '../matches';
5
- import { makeQueries } from './makeQueries';
6
- import type { Queries } from './makeQueries';
7
- import { filterNodeByType } from './filterNodeByType';
8
- import { createLibraryNotSupportedError } from './errors';
9
-
10
- export type TextMatchOptions = {
11
- exact?: boolean,
12
- normalizer?: NormalizerFn,
13
- };
14
-
15
- const getChildrenAsText = (children, TextComponent) => {
16
- const textContent = [];
17
- React.Children.forEach(children, (child) => {
18
- if (typeof child === 'string') {
19
- textContent.push(child);
20
- return;
21
- }
22
-
23
- if (typeof child === 'number') {
24
- textContent.push(child.toString());
25
- return;
26
- }
27
-
28
- if (child?.props?.children) {
29
- // Bail on traversing text children down the tree if current node (child)
30
- // has no text. In such situations, react-test-renderer will traverse down
31
- // this tree in a separate call and run this query again. As a result, the
32
- // query will match the deepest text node that matches requested text.
33
- if (filterNodeByType(child, TextComponent) && textContent.length === 0) {
34
- return;
35
- }
36
-
37
- getChildrenAsText(child.props.children, TextComponent);
38
- }
39
- });
40
-
41
- return textContent;
42
- };
43
-
44
- const getNodeByText = (
45
- node,
46
- text: string | RegExp,
47
- options?: TextMatchOptions = {}
48
- ) => {
49
- try {
50
- const { Text } = require('react-native');
51
- const isTextComponent = filterNodeByType(node, Text);
52
- if (isTextComponent) {
53
- const textChildren = getChildrenAsText(node.props.children, Text);
54
- if (textChildren) {
55
- const textToTest = textChildren.join('');
56
- const { exact, normalizer } = options;
57
- return matches(text, textToTest, normalizer, exact);
58
- }
59
- }
60
- return false;
61
- } catch (error) {
62
- throw createLibraryNotSupportedError(error);
63
- }
64
- };
65
-
66
- const queryAllByText = (
67
- instance: ReactTestInstance
68
- ): ((
69
- text: string | RegExp,
70
- queryOptions?: TextMatchOptions
71
- ) => Array<ReactTestInstance>) =>
72
- function queryAllByTextFn(text, queryOptions) {
73
- const results = instance.findAll((node) =>
74
- getNodeByText(node, text, queryOptions)
75
- );
76
-
77
- return results;
78
- };
79
-
80
- const getMultipleError = (text: string | RegExp) =>
81
- `Found multiple elements with text: ${String(text)}`;
82
- const getMissingError = (text: string | RegExp) =>
83
- `Unable to find an element with text: ${String(text)}`;
84
-
85
- const {
86
- getBy: getByText,
87
- getAllBy: getAllByText,
88
- queryBy: queryByText,
89
- findBy: findByText,
90
- findAllBy: findAllByText,
91
- }: Queries<string | RegExp> = makeQueries(
92
- queryAllByText,
93
- getMissingError,
94
- getMultipleError
95
- );
96
-
97
- export {
98
- findAllByText,
99
- findByText,
100
- getAllByText,
101
- getByText,
102
- queryAllByText,
103
- queryByText,
104
- };
@@ -1,16 +0,0 @@
1
- // @flow
2
- import format from './format';
3
-
4
- /**
5
- * Log pretty-printed deep test component instance
6
- */
7
- export default function debugDeep(
8
- instance: ?ReactTestRendererJSON,
9
- message?: string
10
- ) {
11
- if (message) {
12
- console.log(`${message}\n\n`, format(instance));
13
- } else {
14
- console.log(format(instance));
15
- }
16
- }