-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathtypes.ts
295 lines (274 loc) · 9.25 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
import type { StyleProp } from 'react-native';
import type { ReactTestInstance } from 'react-test-renderer';
import type { AccessibilityValueMatcher } from '../helpers/matchers/match-accessibility-value';
import type { TextMatch, TextMatchOptions } from '../matches';
import type { Style } from './to-have-style';
export interface JestNativeMatchers<R> {
/**
* Assert whether a host element is present in the element tree (screen) or not.
*
* @see
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeonthescreen)
*
* @example
* <Text>Hello</Text>
*
* expect(getByText('Hello')).toBeOnTheScreen()
* expect(queryByText('Other')).not.toBeOnTheScreen()
*/
toBeOnTheScreen(): R;
/**
* Assert whether a host element is checked based on accessibility props.
*
* @see
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobechecked)
*
* @see {@link toBePartiallyChecked} for a related matcher.
*
* @example
* <View accessible role="checkbox" aria-checked aria-label="Enable" />
*
* expect(getByRole('checkbox', { name: "Enable" })).toBeChecked()
*/
toBeChecked(): R;
/**
* Assert whether a host element is collapsed based on accessibility props.
*
* @see
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeexpanded)
*
* @see {@link toBeExpanded} for an inverse matcher.
*
* @example
* <View testID="details" aria-expanded={false} />
*
* expect(getByTestId('details').toBeCollapsed()
*/
toBeCollapsed(): R;
/**
* Assert whether a host element is disabled based on accessibility props.
*
* This matcher will check ancestor elements for their disabled state as well.
*
* @see
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeenabled)
*
* @see {@link toBeEnabled} for an inverse matcher.
*
* @example
* <View role="button" aria-disabled />
*
* expect(getByRole('button').toBeDisabled()
*
*/
toBeDisabled(): R;
/**
* Assert whether a host element is busy based on accessibility props.
*
* This matcher will check ancestor elements for their disabled state as well.
*
* @see
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobebusy)
*
* @example
* <View testID="loader" aria-busy />
*
* expect(getByTestId('loader')).toBeBusy()
*/
toBeBusy(): R;
/**
* Assert whether a host element has no host children or text content.
*
* @see
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeemptyelement)
*
* @example
* <View testID="not-empty">
* <View testID="empty" />
* </View>
*
* expect(getByTestId('empty')).toBeEmptyElement()
* expect(getByTestId('not-mepty')).not.toBeEmptyElement()
*/
toBeEmptyElement(): R;
/**
* Assert whether a host element is enabled based on accessibility props.
*
* This matcher will check ancestor elements for their disabled state as well.
*
* @see
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeenabled)
*
* @see {@link toBeDisabled} for inverse matcher.
*
* @example
* <View role="button" aria-disabled={false} />
*
* expect(getByRole('button').toBeEnabled()
*/
toBeEnabled(): R;
/**
* Assert whether a host element is expanded based on accessibility props.
*
* @see
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeexpanded)
*
* @see {@link toBeCollapsed} for inverse matcher.
*
* @example
* <View testID="details" aria-expanded />
*
* expect(getByTestId('details').toBeExpanded()
*/
toBeExpanded(): R;
/**
* Assert whether a host element is partially checked based on accessibility props.
*
* @see
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobechecked)
*
* @see {@link toBeChecked} for related matcher.
*
* @example
* <View accessible role="checkbox" aria-checked="mixed" aria-label="Enable" />
*
* expect(getByRole('checkbox', { name: "Enable" })).toBePartiallyChecked()
*/
toBePartiallyChecked(): R;
/**
* Assert whether a host element is selected based on accessibility props.
*
* @see
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeselected)
*
* @example
* <View testID="view" aria-selected />
*
* expect(getByTestId('view')).toBeSelected()
*/
toBeSelected(): R;
/**
* Assert whether a host element is visible based on style and accessibility props.
*
* This matcher will check ancestor elements for their visibility as well.
*
* @see
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobevisible)
*
* @example
* <View testID="visible" />
* <View testID="not-visible" style={{ display: 'none' }} />
*
* expect(getByTestId('visible')).toBeVisible()
* expect(getByTestId('not-visible')).not.toBeVisible()
*/
toBeVisible(): R;
/**
* Assert whether a host element contains another host element.
*
* @see
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tocontainelement)
*
* @example
* <View testID="outer">
* <View testID="inner" />
* </View>
*
* expect(getByTestId('outer')).toContainElement(getByTestId('inner'));
*/
toContainElement(element: ReactTestInstance | null): R;
/**
* Assert whether a host element has a given accessbility value.
*
* @see
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohaveaccessibilityvalue)
*
*
* @example
* <View testID="view" aria-valuetext="33%" />
*
* expect(getByTestId('view')).toHaveAccessibilityValue({ text: '33%' });
*/
toHaveAccessibilityValue(expectedValue: AccessibilityValueMatcher): R;
/**
* Assert whether a host element has a given accessibile name based on the accessibility label or text content.
*
* @see
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohaveaccessiblename)
*
* @example
* <View testID="view" aria-label="Hello" />
*
* expect(getByTestId('view')).toHaveAccessibleName('Hello');
*/
toHaveAccessibleName(expectedName?: TextMatch, options?: TextMatchOptions): R;
/**
* Assert whether a host `TextInput` element has a given display value based on `value` prop, unmanaged native state, and `defaultValue` prop.
*
* @see
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohavedisplayvalue)
*
* @example
* <TextInput testID="input" value="Hello" />
*
* expect(getByTestId('input')).toHaveDisplayValue('Hello');
*/
toHaveDisplayValue(expectedValue: TextMatch, options?: TextMatchOptions): R;
/**
* Assert whether a host element has a given prop.
*
* @see
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohaveprop)
*
* @example
* <Text testID="text" numberOfLines={1]} />
*
* expect(getByTestId('text')).toHaveProp('numberOfLines');
* expect(getByTestId('text')).toHaveProp('numberOfLines', 1);
*/
toHaveProp(name: string, expectedValue?: unknown): R;
/**
* Assert whether a host element has a given style.
*
* @see
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohavestyle)
*
* @example
* <View testID="view" style={{ width: '100%' }} />
*
* expect(getByTestId('view')).toHaveStyle({ width: '100%' });
* expect(getByTestId('view')).not.toHaveStyle({ width: '50%' });
*/
toHaveStyle(style: StyleProp<Style>): R;
/**
* Assert whether a host element has a given text content.
*
* @see
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohavetextcontent)
*
* @example
* <View testID="view">
* <Text>Hello World</Text>
* </View>
*
* expect(getByTestId('view')).toHaveTextContent('Hello World');
* expect(getByTestId('view')).toHaveTextContent('Hello', { exact: false }});
* expect(getByTestId('view')).toHaveTextContent(/hello/i);
* expect(getByTestId('view')).not.toHaveTextContent('Hello');
*/
toHaveTextContent(expectedText: TextMatch, options?: TextMatchOptions): R;
}
// Implicit Jest global `expect`.
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace jest {
// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unused-vars
interface Matchers<R, T = {}> extends JestNativeMatchers<R> {}
}
}
// Explicit `@jest/globals` `expect` matchers.
// @ts-expect-error: Invalid module name in augmentation, module '@jest/expect' cannot be found
declare module '@jest/expect' {
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface Matchers<R extends void | Promise<void>> extends JestNativeMatchers<R> {}
}