@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.
- package/README.md +2 -2
- package/build/act.d.ts +3 -0
- package/build/act.js +2 -1
- package/build/act.js.map +1 -0
- package/build/cleanup.d.ts +5 -0
- package/build/cleanup.js +3 -2
- package/build/cleanup.js.map +1 -0
- package/build/fireEvent.d.ts +8 -0
- package/build/fireEvent.js +2 -1
- package/build/fireEvent.js.map +1 -0
- package/build/flushMicroTasks.d.ts +5 -0
- package/build/flushMicroTasks.js +2 -12
- package/build/flushMicroTasks.js.map +1 -0
- package/build/helpers/debugDeep.d.ts +5 -0
- package/build/helpers/debugDeep.js +4 -1
- package/build/helpers/debugDeep.js.map +1 -0
- package/build/helpers/debugShallow.d.ts +6 -0
- package/build/helpers/debugShallow.js +4 -7
- package/build/helpers/debugShallow.js.map +1 -0
- package/build/helpers/errors.d.ts +10 -0
- package/build/helpers/errors.js +29 -9
- package/build/helpers/errors.js.map +1 -0
- package/build/helpers/filterNodeByType.d.ts +3 -0
- package/build/helpers/filterNodeByType.js +2 -1
- package/build/helpers/filterNodeByType.js.map +1 -0
- package/build/helpers/format.d.ts +3 -0
- package/build/helpers/format.js +4 -3
- package/build/helpers/format.js.map +1 -0
- package/build/helpers/timers.d.ts +6 -0
- package/build/helpers/timers.js +9 -6
- package/build/helpers/timers.js.map +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.flow.js +394 -0
- package/build/index.js +2 -1
- package/build/index.js.map +1 -0
- package/build/matches.d.ts +9 -0
- package/build/matches.js +3 -2
- package/build/matches.js.map +1 -0
- package/build/{pure.js.flow → pure.d.ts} +4 -8
- package/build/pure.js +14 -31
- package/build/pure.js.map +1 -0
- package/build/queries/a11yAPI.d.ts +66 -0
- package/build/{helpers → queries}/a11yAPI.js +16 -15
- package/build/queries/a11yAPI.js.map +1 -0
- package/build/queries/displayValue.d.ts +13 -0
- package/build/{helpers/byDisplayValue.js → queries/displayValue.js} +23 -17
- package/build/queries/displayValue.js.map +1 -0
- package/build/queries/makeA11yQuery.d.ts +13 -0
- package/build/{helpers → queries}/makeA11yQuery.js +3 -2
- package/build/queries/makeA11yQuery.js.map +1 -0
- package/build/queries/makeQueries.d.ts +19 -0
- package/build/{helpers → queries}/makeQueries.js +23 -19
- package/build/queries/makeQueries.js.map +1 -0
- package/build/queries/placeholderText.d.ts +13 -0
- package/build/{helpers/byPlaceholderText.js → queries/placeholderText.js} +23 -17
- package/build/queries/placeholderText.js.map +1 -0
- package/build/queries/testId.d.ts +13 -0
- package/build/{helpers/byTestId.js → queries/testId.js} +19 -13
- package/build/queries/testId.js.map +1 -0
- package/build/queries/text.d.ts +17 -0
- package/build/{helpers/byText.js → queries/text.js} +31 -23
- package/build/queries/text.js.map +1 -0
- package/build/queries/unsafeProps.d.ts +16 -0
- package/build/queries/unsafeProps.js +58 -0
- package/build/queries/unsafeProps.js.map +1 -0
- package/build/queries/unsafeType.d.ts +9 -0
- package/build/queries/unsafeType.js +54 -0
- package/build/queries/unsafeType.js.map +1 -0
- package/build/render.d.ts +135 -0
- package/build/render.js +16 -21
- package/build/render.js.map +1 -0
- package/build/renderHook.d.ts +17 -0
- package/build/renderHook.js +57 -0
- package/build/renderHook.js.map +1 -0
- package/build/shallow.d.ts +8 -0
- package/build/shallow.js +3 -9
- package/build/shallow.js.map +1 -0
- package/build/waitFor.d.ts +8 -0
- package/build/waitFor.js +32 -23
- package/build/waitFor.js.map +1 -0
- package/build/waitForElementToBeRemoved.d.ts +2 -0
- package/build/waitForElementToBeRemoved.js +2 -1
- package/build/waitForElementToBeRemoved.js.map +1 -0
- package/build/within.d.ts +117 -0
- package/build/within.js +19 -9
- package/build/within.js.map +1 -0
- package/package.json +24 -14
- package/typings/index.flow.js +394 -0
- package/build/act.js.flow +0 -9
- package/build/cleanup.js.flow +0 -13
- package/build/fireEvent.js.flow +0 -127
- package/build/flushMicroTasks.js.flow +0 -23
- package/build/helpers/a11yAPI.js.flow +0 -241
- package/build/helpers/byDisplayValue.js.flow +0 -66
- package/build/helpers/byPlaceholderText.js.flow +0 -62
- package/build/helpers/byTestId.js.flow +0 -50
- package/build/helpers/byText.js.flow +0 -104
- package/build/helpers/debugDeep.js.flow +0 -16
- package/build/helpers/debugShallow.js.flow +0 -20
- package/build/helpers/errors.js.flow +0 -82
- package/build/helpers/filterNodeByType.js.flow +0 -1
- package/build/helpers/findByAPI.js +0 -32
- package/build/helpers/findByAPI.js.flow +0 -76
- package/build/helpers/format.js.flow +0 -10
- package/build/helpers/getByAPI.js +0 -98
- package/build/helpers/getByAPI.js.flow +0 -157
- package/build/helpers/makeA11yQuery.js.flow +0 -98
- package/build/helpers/makeQueries.js.flow +0 -165
- package/build/helpers/queryByAPI.js +0 -92
- package/build/helpers/queryByAPI.js.flow +0 -166
- package/build/helpers/timers.js.flow +0 -88
- package/build/index.js.flow +0 -18
- package/build/matches.js.flow +0 -41
- package/build/render.js.flow +0 -109
- package/build/shallow.js.flow +0 -26
- package/build/types.flow.js +0 -1
- package/build/types.flow.js.flow +0 -59
- package/build/waitFor.js.flow +0 -221
- package/build/waitForElementToBeRemoved.js.flow +0 -42
- package/build/within.js.flow +0 -18
- package/typings/index.d.ts +0 -432
|
@@ -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
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { shallowInternal } from '../shallow';
|
|
4
|
-
import format from './format';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Log pretty-printed shallow test component instance
|
|
8
|
-
*/
|
|
9
|
-
export default function debugShallow(
|
|
10
|
-
instance: ReactTestInstance | React.Element<any>,
|
|
11
|
-
message?: string
|
|
12
|
-
) {
|
|
13
|
-
const { output } = shallowInternal(instance);
|
|
14
|
-
|
|
15
|
-
if (message) {
|
|
16
|
-
console.log(`${message}\n\n`, format(output));
|
|
17
|
-
} else {
|
|
18
|
-
console.log(format(output));
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import prettyFormat from 'pretty-format';
|
|
3
|
-
|
|
4
|
-
export class ErrorWithStack extends Error {
|
|
5
|
-
constructor(message: ?string, callsite: Function) {
|
|
6
|
-
super(message);
|
|
7
|
-
if (Error.captureStackTrace) {
|
|
8
|
-
Error.captureStackTrace(this, callsite);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const createLibraryNotSupportedError = (error: Error): Error =>
|
|
14
|
-
new Error(
|
|
15
|
-
`Currently the only supported library to search by text is "react-native".\n\n${error.message}`
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
export const prepareErrorMessage = (
|
|
19
|
-
error: Error,
|
|
20
|
-
name: ?string,
|
|
21
|
-
value: ?mixed
|
|
22
|
-
): string => {
|
|
23
|
-
// Strip info about custom predicate
|
|
24
|
-
let errorMessage = error.message.replace(
|
|
25
|
-
/ matching custom predicate[^]*/gm,
|
|
26
|
-
''
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
if (name && value) {
|
|
30
|
-
errorMessage += ` with ${name} ${prettyFormat(value, { min: true })}`;
|
|
31
|
-
}
|
|
32
|
-
return errorMessage;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const createQueryByError = (error: Error, callsite: Function): null => {
|
|
36
|
-
if (error.message.includes('No instances found')) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
throw new ErrorWithStack(error.message, callsite);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export function copyStackTrace(target: Error, stackTraceSource: Error) {
|
|
43
|
-
target.stack = stackTraceSource.stack.replace(
|
|
44
|
-
stackTraceSource.message,
|
|
45
|
-
target.message
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const warned = {};
|
|
50
|
-
|
|
51
|
-
export function printDeprecationWarning(functionName: string) {
|
|
52
|
-
if (warned[functionName]) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// eslint-disable-next-line no-console
|
|
57
|
-
console.warn(`
|
|
58
|
-
Deprecation Warning:
|
|
59
|
-
Use of ${functionName} is not recommended and will be deleted in future versions of @testing-library/react-native.
|
|
60
|
-
`);
|
|
61
|
-
|
|
62
|
-
warned[functionName] = true;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function throwRemovedFunctionError(
|
|
66
|
-
functionName: string,
|
|
67
|
-
docsRef: string
|
|
68
|
-
) {
|
|
69
|
-
throw new Error(
|
|
70
|
-
`"${functionName}" has been removed.\n\nPlease consult: https://callstack.github.io/react-native-testing-library/docs/${docsRef}`
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function throwRenamedFunctionError(
|
|
75
|
-
functionName: string,
|
|
76
|
-
newFunctionName: string
|
|
77
|
-
) {
|
|
78
|
-
throw new ErrorWithStack(
|
|
79
|
-
`The "${functionName}" function has been renamed to "${newFunctionName}". Please replace all occurrences.`,
|
|
80
|
-
throwRenamedFunctionError
|
|
81
|
-
);
|
|
82
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const filterNodeByType = (node, type) => node.type === type;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.findByAPI = void 0;
|
|
7
|
-
|
|
8
|
-
var _byTestId = require("./byTestId");
|
|
9
|
-
|
|
10
|
-
var _byText = require("./byText");
|
|
11
|
-
|
|
12
|
-
var _byPlaceholderText = require("./byPlaceholderText");
|
|
13
|
-
|
|
14
|
-
var _byDisplayValue = require("./byDisplayValue");
|
|
15
|
-
|
|
16
|
-
var _errors = require("./errors");
|
|
17
|
-
|
|
18
|
-
const findByAPI = instance => ({
|
|
19
|
-
findByTestId: (0, _byTestId.findByTestId)(instance),
|
|
20
|
-
findByText: (0, _byText.findByText)(instance),
|
|
21
|
-
findByPlaceholderText: (0, _byPlaceholderText.findByPlaceholderText)(instance),
|
|
22
|
-
findByDisplayValue: (0, _byDisplayValue.findByDisplayValue)(instance),
|
|
23
|
-
findAllByTestId: (0, _byTestId.findAllByTestId)(instance),
|
|
24
|
-
findAllByText: (0, _byText.findAllByText)(instance),
|
|
25
|
-
findAllByPlaceholderText: (0, _byPlaceholderText.findAllByPlaceholderText)(instance),
|
|
26
|
-
findAllByDisplayValue: (0, _byDisplayValue.findAllByDisplayValue)(instance),
|
|
27
|
-
// Renamed
|
|
28
|
-
findByPlaceholder: () => (0, _errors.throwRenamedFunctionError)('findByPlaceholder', 'findByPlaceholderText'),
|
|
29
|
-
findAllByPlaceholder: () => (0, _errors.throwRenamedFunctionError)('findAllByPlaceholder', 'findAllByPlaceholderText')
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
exports.findByAPI = findByAPI;
|