@testing-library/react-native 12.4.1 → 12.4.3
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/build/matchers/types.d.ts +233 -1
- package/build/matchers/types.js.map +1 -1
- package/build/user-event/event-builder/index.d.ts +1 -1
- package/build/user-event/event-builder/scroll-view.d.ts +19 -6
- package/build/user-event/event-builder/scroll-view.js +12 -9
- package/build/user-event/event-builder/scroll-view.js.map +1 -1
- package/build/user-event/scroll/scroll-to.d.ts +13 -2
- package/build/user-event/scroll/scroll-to.js +11 -10
- package/build/user-event/scroll/scroll-to.js.map +1 -1
- package/build/user-event/utils/dispatch-event.d.ts +2 -2
- package/build/user-event/utils/dispatch-event.js +3 -3
- package/build/user-event/utils/dispatch-event.js.map +1 -1
- package/package.json +41 -35
|
@@ -5,25 +5,257 @@ import { TextMatch, TextMatchOptions } from '../matches';
|
|
|
5
5
|
import { Style } from './to-have-style';
|
|
6
6
|
export interface JestNativeMatchers<R> {
|
|
7
7
|
/**
|
|
8
|
-
* Assert whether
|
|
8
|
+
* Assert whether a host element is present in the element tree (screen) or not.
|
|
9
|
+
*
|
|
10
|
+
* @see
|
|
11
|
+
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeonthescreen)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* <Text>Hello</Text>
|
|
15
|
+
*
|
|
16
|
+
* expect(getByText('Hello')).toBeOnTheScreen()
|
|
17
|
+
* expect(queryByText('Other')).not.toBeOnTheScreen()
|
|
9
18
|
*/
|
|
10
19
|
toBeOnTheScreen(): R;
|
|
20
|
+
/**
|
|
21
|
+
* Assert whether a host element is checked based on accessibility props.
|
|
22
|
+
*
|
|
23
|
+
* @see
|
|
24
|
+
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobechecked)
|
|
25
|
+
*
|
|
26
|
+
* @see {@link toBePartiallyChecked} for a related matcher.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* <View accessible role="checkbox" aria-checked aria-label="Enable" />
|
|
30
|
+
*
|
|
31
|
+
* expect(getByRole('checkbox', { name: "Enable" })).toBeChecked()
|
|
32
|
+
*/
|
|
11
33
|
toBeChecked(): R;
|
|
34
|
+
/**
|
|
35
|
+
* Assert whether a host element is collapsed based on accessibility props.
|
|
36
|
+
*
|
|
37
|
+
* @see
|
|
38
|
+
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeexpanded)
|
|
39
|
+
*
|
|
40
|
+
* @see {@link toBeExpanded} for an inverse matcher.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* <View testID="details" aria-expanded={false} />
|
|
44
|
+
*
|
|
45
|
+
* expect(getByTestId('details').toBeCollapsed()
|
|
46
|
+
*/
|
|
12
47
|
toBeCollapsed(): R;
|
|
48
|
+
/**
|
|
49
|
+
* Assert whether a host element is disabled based on accessibility props.
|
|
50
|
+
*
|
|
51
|
+
* This matcher will check ancestor elements for their disabled state as well.
|
|
52
|
+
*
|
|
53
|
+
* @see
|
|
54
|
+
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeenabled)
|
|
55
|
+
*
|
|
56
|
+
* @see {@link toBeEnabled} for an inverse matcher.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* <View role="button" aria-disabled />
|
|
60
|
+
*
|
|
61
|
+
* expect(getByRole('button').toBeDisabled()
|
|
62
|
+
*
|
|
63
|
+
*/
|
|
13
64
|
toBeDisabled(): R;
|
|
65
|
+
/**
|
|
66
|
+
* Assert whether a host element is busy based on accessibility props.
|
|
67
|
+
*
|
|
68
|
+
* This matcher will check ancestor elements for their disabled state as well.
|
|
69
|
+
*
|
|
70
|
+
* @see
|
|
71
|
+
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobebusy)
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* <View testID="loader" aria-busy />
|
|
75
|
+
*
|
|
76
|
+
* expect(getByTestId('loader')).toBeBusy()
|
|
77
|
+
*/
|
|
14
78
|
toBeBusy(): R;
|
|
79
|
+
/**
|
|
80
|
+
* Assert whether a host element has no host children or text content.
|
|
81
|
+
*
|
|
82
|
+
* @see
|
|
83
|
+
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeemptyelement)
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* <View testID="not-empty">
|
|
87
|
+
* <View testID="empty" />
|
|
88
|
+
* </View>
|
|
89
|
+
*
|
|
90
|
+
* expect(getByTestId('empty')).toBeEmptyElement()
|
|
91
|
+
* expect(getByTestId('not-mepty')).not.toBeEmptyElement()
|
|
92
|
+
*/
|
|
15
93
|
toBeEmptyElement(): R;
|
|
94
|
+
/**
|
|
95
|
+
* Assert whether a host element is enabled based on accessibility props.
|
|
96
|
+
*
|
|
97
|
+
* This matcher will check ancestor elements for their disabled state as well.
|
|
98
|
+
*
|
|
99
|
+
* @see
|
|
100
|
+
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeenabled)
|
|
101
|
+
*
|
|
102
|
+
* @see {@link toBeDisabled} for inverse matcher.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* <View role="button" aria-disabled={false} />
|
|
106
|
+
*
|
|
107
|
+
* expect(getByRole('button').toBeEnabled()
|
|
108
|
+
*/
|
|
16
109
|
toBeEnabled(): R;
|
|
110
|
+
/**
|
|
111
|
+
* Assert whether a host element is expanded based on accessibility props.
|
|
112
|
+
*
|
|
113
|
+
* @see
|
|
114
|
+
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeexpanded)
|
|
115
|
+
*
|
|
116
|
+
* @see {@link toBeCollapsed} for inverse matcher.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* <View testID="details" aria-expanded />
|
|
120
|
+
*
|
|
121
|
+
* expect(getByTestId('details').toBeExpanded()
|
|
122
|
+
*/
|
|
17
123
|
toBeExpanded(): R;
|
|
124
|
+
/**
|
|
125
|
+
* Assert whether a host element is partially checked based on accessibility props.
|
|
126
|
+
*
|
|
127
|
+
* @see
|
|
128
|
+
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobechecked)
|
|
129
|
+
*
|
|
130
|
+
* @see {@link toBeChecked} for related matcher.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* <View accessible role="checkbox" aria-checked="mixed" aria-label="Enable" />
|
|
134
|
+
*
|
|
135
|
+
* expect(getByRole('checkbox', { name: "Enable" })).toBePartiallyChecked()
|
|
136
|
+
*/
|
|
18
137
|
toBePartiallyChecked(): R;
|
|
138
|
+
/**
|
|
139
|
+
* Assert whether a host element is selected based on accessibility props.
|
|
140
|
+
*
|
|
141
|
+
* @see
|
|
142
|
+
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeselected)
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* <View testID="view" aria-selected />
|
|
146
|
+
*
|
|
147
|
+
* expect(getByTestId('view')).toBeSelected()
|
|
148
|
+
*/
|
|
19
149
|
toBeSelected(): R;
|
|
150
|
+
/**
|
|
151
|
+
* Assert whether a host element is visible based on style and accessibility props.
|
|
152
|
+
*
|
|
153
|
+
* This matcher will check ancestor elements for their visibility as well.
|
|
154
|
+
*
|
|
155
|
+
* @see
|
|
156
|
+
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobevisible)
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* <View testID="visible" />
|
|
160
|
+
* <View testID="not-visible" style={{ display: 'none' }} />
|
|
161
|
+
*
|
|
162
|
+
* expect(getByTestId('visible')).toBeVisible()
|
|
163
|
+
* expect(getByTestId('not-visible')).not.toBeVisible()
|
|
164
|
+
*/
|
|
20
165
|
toBeVisible(): R;
|
|
166
|
+
/**
|
|
167
|
+
* Assert whether a host element contains another host element.
|
|
168
|
+
*
|
|
169
|
+
* @see
|
|
170
|
+
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tocontainelement)
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* <View testID="outer">
|
|
174
|
+
* <View testID="inner" />
|
|
175
|
+
* </View>
|
|
176
|
+
*
|
|
177
|
+
* expect(getByTestId('outer')).toContainElement(getByTestId('inner'));
|
|
178
|
+
*/
|
|
21
179
|
toContainElement(element: ReactTestInstance | null): R;
|
|
180
|
+
/**
|
|
181
|
+
* Assert whether a host element has a given accessbility value.
|
|
182
|
+
*
|
|
183
|
+
* @see
|
|
184
|
+
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohaveaccessibilityvalue)
|
|
185
|
+
*
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* <View testID="view" aria-valuetext="33%" />
|
|
189
|
+
*
|
|
190
|
+
* expect(getByTestId('view')).toHaveAccessibilityValue({ text: '33%' });
|
|
191
|
+
*/
|
|
22
192
|
toHaveAccessibilityValue(expectedValue: AccessibilityValueMatcher): R;
|
|
193
|
+
/**
|
|
194
|
+
* Assert whether a host element has a given accessibile name based on the accessibility label or text content.
|
|
195
|
+
*
|
|
196
|
+
* @see
|
|
197
|
+
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohaveaccessiblename)
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* <View testID="view" aria-label="Hello" />
|
|
201
|
+
*
|
|
202
|
+
* expect(getByTestId('view')).toHaveAccessibleName('Hello');
|
|
203
|
+
*/
|
|
23
204
|
toHaveAccessibleName(expectedName?: TextMatch, options?: TextMatchOptions): R;
|
|
205
|
+
/**
|
|
206
|
+
* Assert whether a host `TextInput` element has a given display value based on `value` and `defaultValue` props.
|
|
207
|
+
*
|
|
208
|
+
* @see
|
|
209
|
+
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohavedisplayvalue)
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* <TextInput testID="input" value="Hello" />
|
|
213
|
+
*
|
|
214
|
+
* expect(getByTestId('input')).toHaveDisplayValue('Hello');
|
|
215
|
+
*/
|
|
24
216
|
toHaveDisplayValue(expectedValue: TextMatch, options?: TextMatchOptions): R;
|
|
217
|
+
/**
|
|
218
|
+
* Assert whether a host element has a given prop.
|
|
219
|
+
*
|
|
220
|
+
* @see
|
|
221
|
+
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohaveprop)
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* <Text testID="text" numberOfLines={1]} />
|
|
225
|
+
*
|
|
226
|
+
* expect(getByTestId('text')).toHaveProp('numberOfLines');
|
|
227
|
+
* expect(getByTestId('text')).toHaveProp('numberOfLines', 1);
|
|
228
|
+
*/
|
|
25
229
|
toHaveProp(name: string, expectedValue?: unknown): R;
|
|
230
|
+
/**
|
|
231
|
+
* Assert whether a host element has a given style.
|
|
232
|
+
*
|
|
233
|
+
* @see
|
|
234
|
+
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohavestyle)
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* <View testID="view" style={{ width: '100%' }} />
|
|
238
|
+
*
|
|
239
|
+
* expect(getByTestId('view')).toHaveStyle({ width: '100%' });
|
|
240
|
+
* expect(getByTestId('view')).not.toHaveStyle({ width: '50%' });
|
|
241
|
+
*/
|
|
26
242
|
toHaveStyle(style: StyleProp<Style>): R;
|
|
243
|
+
/**
|
|
244
|
+
* Assert whether a host element has a given text content.
|
|
245
|
+
*
|
|
246
|
+
* @see
|
|
247
|
+
* [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohavetextcontent)
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* <View testID="view">
|
|
251
|
+
* <Text>Hello World</Text>
|
|
252
|
+
* </View>
|
|
253
|
+
*
|
|
254
|
+
* expect(getByTestId('view')).toHaveTextContent('Hello World');
|
|
255
|
+
* expect(getByTestId('view')).toHaveTextContent('Hello', { exact: false }});
|
|
256
|
+
* expect(getByTestId('view')).toHaveTextContent(/hello/i);
|
|
257
|
+
* expect(getByTestId('view')).not.toHaveTextContent('Hello');
|
|
258
|
+
*/
|
|
27
259
|
toHaveTextContent(expectedText: TextMatch, options?: TextMatchOptions): R;
|
|
28
260
|
}
|
|
29
261
|
declare global {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../src/matchers/types.ts"],"sourcesContent":["import type { StyleProp } from 'react-native';\nimport type { ReactTestInstance } from 'react-test-renderer';\nimport { AccessibilityValueMatcher } from '../helpers/matchers/match-accessibility-value';\nimport { TextMatch, TextMatchOptions } from '../matches';\nimport { Style } from './to-have-style';\n\nexport interface JestNativeMatchers<R> {\n /**\n * Assert whether
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/matchers/types.ts"],"sourcesContent":["import type { StyleProp } from 'react-native';\nimport type { ReactTestInstance } from 'react-test-renderer';\nimport { AccessibilityValueMatcher } from '../helpers/matchers/match-accessibility-value';\nimport { TextMatch, TextMatchOptions } from '../matches';\nimport { Style } from './to-have-style';\n\nexport interface JestNativeMatchers<R> {\n /**\n * Assert whether a host element is present in the element tree (screen) or not.\n *\n * @see\n * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeonthescreen)\n *\n * @example\n * <Text>Hello</Text>\n *\n * expect(getByText('Hello')).toBeOnTheScreen()\n * expect(queryByText('Other')).not.toBeOnTheScreen()\n */\n toBeOnTheScreen(): R;\n\n /**\n * Assert whether a host element is checked based on accessibility props.\n *\n * @see\n * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobechecked)\n *\n * @see {@link toBePartiallyChecked} for a related matcher.\n *\n * @example\n * <View accessible role=\"checkbox\" aria-checked aria-label=\"Enable\" />\n *\n * expect(getByRole('checkbox', { name: \"Enable\" })).toBeChecked()\n */\n toBeChecked(): R;\n\n /**\n * Assert whether a host element is collapsed based on accessibility props.\n *\n * @see\n * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeexpanded)\n *\n * @see {@link toBeExpanded} for an inverse matcher.\n *\n * @example\n * <View testID=\"details\" aria-expanded={false} />\n *\n * expect(getByTestId('details').toBeCollapsed()\n */\n toBeCollapsed(): R;\n\n /**\n * Assert whether a host element is disabled based on accessibility props.\n *\n * This matcher will check ancestor elements for their disabled state as well.\n *\n * @see\n * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeenabled)\n *\n * @see {@link toBeEnabled} for an inverse matcher.\n *\n * @example\n * <View role=\"button\" aria-disabled />\n *\n * expect(getByRole('button').toBeDisabled()\n *\n */\n toBeDisabled(): R;\n\n /**\n * Assert whether a host element is busy based on accessibility props.\n *\n * This matcher will check ancestor elements for their disabled state as well.\n *\n * @see\n * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobebusy)\n *\n * @example\n * <View testID=\"loader\" aria-busy />\n *\n * expect(getByTestId('loader')).toBeBusy()\n */\n toBeBusy(): R;\n\n /**\n * Assert whether a host element has no host children or text content.\n *\n * @see\n * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeemptyelement)\n *\n * @example\n * <View testID=\"not-empty\">\n * <View testID=\"empty\" />\n * </View>\n *\n * expect(getByTestId('empty')).toBeEmptyElement()\n * expect(getByTestId('not-mepty')).not.toBeEmptyElement()\n */\n toBeEmptyElement(): R;\n\n /**\n * Assert whether a host element is enabled based on accessibility props.\n *\n * This matcher will check ancestor elements for their disabled state as well.\n *\n * @see\n * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeenabled)\n *\n * @see {@link toBeDisabled} for inverse matcher.\n *\n * @example\n * <View role=\"button\" aria-disabled={false} />\n *\n * expect(getByRole('button').toBeEnabled()\n */\n toBeEnabled(): R;\n\n /**\n * Assert whether a host element is expanded based on accessibility props.\n *\n * @see\n * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeexpanded)\n *\n * @see {@link toBeCollapsed} for inverse matcher.\n *\n * @example\n * <View testID=\"details\" aria-expanded />\n *\n * expect(getByTestId('details').toBeExpanded()\n */\n toBeExpanded(): R;\n\n /**\n * Assert whether a host element is partially checked based on accessibility props.\n *\n * @see\n * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobechecked)\n *\n * @see {@link toBeChecked} for related matcher.\n *\n * @example\n * <View accessible role=\"checkbox\" aria-checked=\"mixed\" aria-label=\"Enable\" />\n *\n * expect(getByRole('checkbox', { name: \"Enable\" })).toBePartiallyChecked()\n */\n toBePartiallyChecked(): R;\n\n /**\n * Assert whether a host element is selected based on accessibility props.\n *\n * @see\n * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeselected)\n *\n * @example\n * <View testID=\"view\" aria-selected />\n *\n * expect(getByTestId('view')).toBeSelected()\n */\n toBeSelected(): R;\n\n /**\n * Assert whether a host element is visible based on style and accessibility props.\n *\n * This matcher will check ancestor elements for their visibility as well.\n *\n * @see\n * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobevisible)\n *\n * @example\n * <View testID=\"visible\" />\n * <View testID=\"not-visible\" style={{ display: 'none' }} />\n *\n * expect(getByTestId('visible')).toBeVisible()\n * expect(getByTestId('not-visible')).not.toBeVisible()\n */\n toBeVisible(): R;\n\n /**\n * Assert whether a host element contains another host element.\n *\n * @see\n * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tocontainelement)\n *\n * @example\n * <View testID=\"outer\">\n * <View testID=\"inner\" />\n * </View>\n *\n * expect(getByTestId('outer')).toContainElement(getByTestId('inner'));\n */\n toContainElement(element: ReactTestInstance | null): R;\n\n /**\n * Assert whether a host element has a given accessbility value.\n *\n * @see\n * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohaveaccessibilityvalue)\n *\n *\n * @example\n * <View testID=\"view\" aria-valuetext=\"33%\" />\n *\n * expect(getByTestId('view')).toHaveAccessibilityValue({ text: '33%' });\n */\n toHaveAccessibilityValue(expectedValue: AccessibilityValueMatcher): R;\n\n /**\n * Assert whether a host element has a given accessibile name based on the accessibility label or text content.\n *\n * @see\n * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohaveaccessiblename)\n *\n * @example\n * <View testID=\"view\" aria-label=\"Hello\" />\n *\n * expect(getByTestId('view')).toHaveAccessibleName('Hello');\n */\n toHaveAccessibleName(expectedName?: TextMatch, options?: TextMatchOptions): R;\n\n /**\n * Assert whether a host `TextInput` element has a given display value based on `value` and `defaultValue` props.\n *\n * @see\n * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohavedisplayvalue)\n *\n * @example\n * <TextInput testID=\"input\" value=\"Hello\" />\n *\n * expect(getByTestId('input')).toHaveDisplayValue('Hello');\n */\n toHaveDisplayValue(expectedValue: TextMatch, options?: TextMatchOptions): R;\n\n /**\n * Assert whether a host element has a given prop.\n *\n * @see\n * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohaveprop)\n *\n * @example\n * <Text testID=\"text\" numberOfLines={1]} />\n *\n * expect(getByTestId('text')).toHaveProp('numberOfLines');\n * expect(getByTestId('text')).toHaveProp('numberOfLines', 1);\n */\n toHaveProp(name: string, expectedValue?: unknown): R;\n\n /**\n * Assert whether a host element has a given style.\n *\n * @see\n * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohavestyle)\n *\n * @example\n * <View testID=\"view\" style={{ width: '100%' }} />\n *\n * expect(getByTestId('view')).toHaveStyle({ width: '100%' });\n * expect(getByTestId('view')).not.toHaveStyle({ width: '50%' });\n */\n toHaveStyle(style: StyleProp<Style>): R;\n\n /**\n * Assert whether a host element has a given text content.\n *\n * @see\n * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohavetextcontent)\n *\n * @example\n * <View testID=\"view\">\n * <Text>Hello World</Text>\n * </View>\n *\n * expect(getByTestId('view')).toHaveTextContent('Hello World');\n * expect(getByTestId('view')).toHaveTextContent('Hello', { exact: false }});\n * expect(getByTestId('view')).toHaveTextContent(/hello/i);\n * expect(getByTestId('view')).not.toHaveTextContent('Hello');\n */\n toHaveTextContent(expectedText: TextMatch, options?: TextMatchOptions): R;\n}\n\n// Implicit Jest global `expect`.\ndeclare global {\n namespace jest {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Matchers<R, T = {}> extends JestNativeMatchers<R> {}\n }\n}\n\n// Explicit `@jest/globals` `expect` matchers.\n// @ts-ignore\ndeclare module '@jest/expect' {\n interface Matchers<R extends void | Promise<void>>\n extends JestNativeMatchers<R> {}\n}\n"],"mappings":""}
|
|
@@ -77,7 +77,7 @@ export declare const EventBuilder: {
|
|
|
77
77
|
};
|
|
78
78
|
};
|
|
79
79
|
ScrollView: {
|
|
80
|
-
scroll: (offset?: import("./scroll-view").ContentOffset) => {
|
|
80
|
+
scroll: (offset?: import("./scroll-view").ContentOffset, options?: import("./scroll-view").ScrollEventOptions | undefined) => {
|
|
81
81
|
nativeEvent: {
|
|
82
82
|
contentInset: {
|
|
83
83
|
bottom: number;
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Experimental values:
|
|
3
|
-
* - iOS: `{"contentInset": {"bottom": 0, "left": 0, "right": 0, "top": 0}, "contentOffset": {"x": 0, "y": 5.333333333333333}, "contentSize": {"height": 1676.6666259765625, "width": 390}, "layoutMeasurement": {"height": 753, "width": 390}, "zoomScale": 1}`
|
|
4
|
-
* - Android: `{"contentInset": {"bottom": 0, "left": 0, "right": 0, "top": 0}, "contentOffset": {"x": 0, "y": 31.619047164916992}, "contentSize": {"height": 1624.761962890625, "width": 411.4285583496094}, "layoutMeasurement": {"height": 785.5238037109375, "width": 411.4285583496094}, "responderIgnoreScroll": true, "target": 139, "velocity": {"x": -1.3633992671966553, "y": -1.3633992671966553}}`
|
|
5
|
-
*/
|
|
6
1
|
/**
|
|
7
2
|
* Scroll position of a scrollable element.
|
|
8
3
|
*/
|
|
@@ -10,8 +5,26 @@ export interface ContentOffset {
|
|
|
10
5
|
y: number;
|
|
11
6
|
x: number;
|
|
12
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Other options for constructing a scroll event.
|
|
10
|
+
*/
|
|
11
|
+
export type ScrollEventOptions = {
|
|
12
|
+
contentSize?: {
|
|
13
|
+
height: number;
|
|
14
|
+
width: number;
|
|
15
|
+
};
|
|
16
|
+
layoutMeasurement?: {
|
|
17
|
+
height: number;
|
|
18
|
+
width: number;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Experimental values:
|
|
23
|
+
* - iOS: `{"contentInset": {"bottom": 0, "left": 0, "right": 0, "top": 0}, "contentOffset": {"x": 0, "y": 5.333333333333333}, "contentSize": {"height": 1676.6666259765625, "width": 390}, "layoutMeasurement": {"height": 753, "width": 390}, "zoomScale": 1}`
|
|
24
|
+
* - Android: `{"contentInset": {"bottom": 0, "left": 0, "right": 0, "top": 0}, "contentOffset": {"x": 0, "y": 31.619047164916992}, "contentSize": {"height": 1624.761962890625, "width": 411.4285583496094}, "layoutMeasurement": {"height": 785.5238037109375, "width": 411.4285583496094}, "responderIgnoreScroll": true, "target": 139, "velocity": {"x": -1.3633992671966553, "y": -1.3633992671966553}}`
|
|
25
|
+
*/
|
|
13
26
|
export declare const ScrollViewEventBuilder: {
|
|
14
|
-
scroll: (offset?: ContentOffset) => {
|
|
27
|
+
scroll: (offset?: ContentOffset, options?: ScrollEventOptions) => {
|
|
15
28
|
nativeEvent: {
|
|
16
29
|
contentInset: {
|
|
17
30
|
bottom: number;
|
|
@@ -5,20 +5,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.ScrollViewEventBuilder = void 0;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* - iOS: `{"contentInset": {"bottom": 0, "left": 0, "right": 0, "top": 0}, "contentOffset": {"x": 0, "y": 5.333333333333333}, "contentSize": {"height": 1676.6666259765625, "width": 390}, "layoutMeasurement": {"height": 753, "width": 390}, "zoomScale": 1}`
|
|
10
|
-
* - Android: `{"contentInset": {"bottom": 0, "left": 0, "right": 0, "top": 0}, "contentOffset": {"x": 0, "y": 31.619047164916992}, "contentSize": {"height": 1624.761962890625, "width": 411.4285583496094}, "layoutMeasurement": {"height": 785.5238037109375, "width": 411.4285583496094}, "responderIgnoreScroll": true, "target": 139, "velocity": {"x": -1.3633992671966553, "y": -1.3633992671966553}}`
|
|
8
|
+
* Scroll position of a scrollable element.
|
|
11
9
|
*/
|
|
12
10
|
|
|
13
11
|
/**
|
|
14
|
-
*
|
|
12
|
+
* Other options for constructing a scroll event.
|
|
15
13
|
*/
|
|
16
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Experimental values:
|
|
17
|
+
* - iOS: `{"contentInset": {"bottom": 0, "left": 0, "right": 0, "top": 0}, "contentOffset": {"x": 0, "y": 5.333333333333333}, "contentSize": {"height": 1676.6666259765625, "width": 390}, "layoutMeasurement": {"height": 753, "width": 390}, "zoomScale": 1}`
|
|
18
|
+
* - Android: `{"contentInset": {"bottom": 0, "left": 0, "right": 0, "top": 0}, "contentOffset": {"x": 0, "y": 31.619047164916992}, "contentSize": {"height": 1624.761962890625, "width": 411.4285583496094}, "layoutMeasurement": {"height": 785.5238037109375, "width": 411.4285583496094}, "responderIgnoreScroll": true, "target": 139, "velocity": {"x": -1.3633992671966553, "y": -1.3633992671966553}}`
|
|
19
|
+
*/
|
|
17
20
|
const ScrollViewEventBuilder = exports.ScrollViewEventBuilder = {
|
|
18
21
|
scroll: (offset = {
|
|
19
22
|
y: 0,
|
|
20
23
|
x: 0
|
|
21
|
-
}) => {
|
|
24
|
+
}, options) => {
|
|
22
25
|
return {
|
|
23
26
|
nativeEvent: {
|
|
24
27
|
contentInset: {
|
|
@@ -32,12 +35,12 @@ const ScrollViewEventBuilder = exports.ScrollViewEventBuilder = {
|
|
|
32
35
|
x: offset.x
|
|
33
36
|
},
|
|
34
37
|
contentSize: {
|
|
35
|
-
height: 0,
|
|
36
|
-
width: 0
|
|
38
|
+
height: options?.contentSize?.height ?? 0,
|
|
39
|
+
width: options?.contentSize?.width ?? 0
|
|
37
40
|
},
|
|
38
41
|
layoutMeasurement: {
|
|
39
|
-
height: 0,
|
|
40
|
-
width: 0
|
|
42
|
+
height: options?.layoutMeasurement?.height ?? 0,
|
|
43
|
+
width: options?.layoutMeasurement?.width ?? 0
|
|
41
44
|
},
|
|
42
45
|
responderIgnoreScroll: true,
|
|
43
46
|
target: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroll-view.js","names":["ScrollViewEventBuilder","exports","scroll","offset","y","x","nativeEvent","contentInset","bottom","left","right","top","contentOffset","contentSize","height","width","layoutMeasurement","responderIgnoreScroll","target","velocity","currentTarget"],"sources":["../../../src/user-event/event-builder/scroll-view.ts"],"sourcesContent":["/**\n * Experimental values:\n * - iOS: `{\"contentInset\": {\"bottom\": 0, \"left\": 0, \"right\": 0, \"top\": 0}, \"contentOffset\": {\"x\": 0, \"y\": 5.333333333333333}, \"contentSize\": {\"height\": 1676.6666259765625, \"width\": 390}, \"layoutMeasurement\": {\"height\": 753, \"width\": 390}, \"zoomScale\": 1}`\n * - Android: `{\"contentInset\": {\"bottom\": 0, \"left\": 0, \"right\": 0, \"top\": 0}, \"contentOffset\": {\"x\": 0, \"y\": 31.619047164916992}, \"contentSize\": {\"height\": 1624.761962890625, \"width\": 411.4285583496094}, \"layoutMeasurement\": {\"height\": 785.5238037109375, \"width\": 411.4285583496094}, \"responderIgnoreScroll\": true, \"target\": 139, \"velocity\": {\"x\": -1.3633992671966553, \"y\": -1.3633992671966553}}`\n */\
|
|
1
|
+
{"version":3,"file":"scroll-view.js","names":["ScrollViewEventBuilder","exports","scroll","offset","y","x","options","nativeEvent","contentInset","bottom","left","right","top","contentOffset","contentSize","height","width","layoutMeasurement","responderIgnoreScroll","target","velocity","currentTarget"],"sources":["../../../src/user-event/event-builder/scroll-view.ts"],"sourcesContent":["/**\n * Scroll position of a scrollable element.\n */\nexport interface ContentOffset {\n y: number;\n x: number;\n}\n\n/**\n * Other options for constructing a scroll event.\n */\nexport type ScrollEventOptions = {\n contentSize?: {\n height: number;\n width: number;\n };\n layoutMeasurement?: {\n height: number;\n width: number;\n };\n};\n\n/**\n * Experimental values:\n * - iOS: `{\"contentInset\": {\"bottom\": 0, \"left\": 0, \"right\": 0, \"top\": 0}, \"contentOffset\": {\"x\": 0, \"y\": 5.333333333333333}, \"contentSize\": {\"height\": 1676.6666259765625, \"width\": 390}, \"layoutMeasurement\": {\"height\": 753, \"width\": 390}, \"zoomScale\": 1}`\n * - Android: `{\"contentInset\": {\"bottom\": 0, \"left\": 0, \"right\": 0, \"top\": 0}, \"contentOffset\": {\"x\": 0, \"y\": 31.619047164916992}, \"contentSize\": {\"height\": 1624.761962890625, \"width\": 411.4285583496094}, \"layoutMeasurement\": {\"height\": 785.5238037109375, \"width\": 411.4285583496094}, \"responderIgnoreScroll\": true, \"target\": 139, \"velocity\": {\"x\": -1.3633992671966553, \"y\": -1.3633992671966553}}`\n */\nexport const ScrollViewEventBuilder = {\n scroll: (\n offset: ContentOffset = { y: 0, x: 0 },\n options?: ScrollEventOptions\n ) => {\n return {\n nativeEvent: {\n contentInset: { bottom: 0, left: 0, right: 0, top: 0 },\n contentOffset: { y: offset.y, x: offset.x },\n contentSize: {\n height: options?.contentSize?.height ?? 0,\n width: options?.contentSize?.width ?? 0,\n },\n layoutMeasurement: {\n height: options?.layoutMeasurement?.height ?? 0,\n width: options?.layoutMeasurement?.width ?? 0,\n },\n responderIgnoreScroll: true,\n target: 0,\n velocity: { y: 0, x: 0 },\n },\n currentTarget: {},\n target: {},\n };\n },\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;;AAMA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;AACO,MAAMA,sBAAsB,GAAAC,OAAA,CAAAD,sBAAA,GAAG;EACpCE,MAAM,EAAEA,CACNC,MAAqB,GAAG;IAAEC,CAAC,EAAE,CAAC;IAAEC,CAAC,EAAE;EAAE,CAAC,EACtCC,OAA4B,KACzB;IACH,OAAO;MACLC,WAAW,EAAE;QACXC,YAAY,EAAE;UAAEC,MAAM,EAAE,CAAC;UAAEC,IAAI,EAAE,CAAC;UAAEC,KAAK,EAAE,CAAC;UAAEC,GAAG,EAAE;QAAE,CAAC;QACtDC,aAAa,EAAE;UAAET,CAAC,EAAED,MAAM,CAACC,CAAC;UAAEC,CAAC,EAAEF,MAAM,CAACE;QAAE,CAAC;QAC3CS,WAAW,EAAE;UACXC,MAAM,EAAET,OAAO,EAAEQ,WAAW,EAAEC,MAAM,IAAI,CAAC;UACzCC,KAAK,EAAEV,OAAO,EAAEQ,WAAW,EAAEE,KAAK,IAAI;QACxC,CAAC;QACDC,iBAAiB,EAAE;UACjBF,MAAM,EAAET,OAAO,EAAEW,iBAAiB,EAAEF,MAAM,IAAI,CAAC;UAC/CC,KAAK,EAAEV,OAAO,EAAEW,iBAAiB,EAAED,KAAK,IAAI;QAC9C,CAAC;QACDE,qBAAqB,EAAE,IAAI;QAC3BC,MAAM,EAAE,CAAC;QACTC,QAAQ,EAAE;UAAEhB,CAAC,EAAE,CAAC;UAAEC,CAAC,EAAE;QAAE;MACzB,CAAC;MACDgB,aAAa,EAAE,CAAC,CAAC;MACjBF,MAAM,EAAE,CAAC;IACX,CAAC;EACH;AACF,CAAC"}
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import { ReactTestInstance } from 'react-test-renderer';
|
|
2
2
|
import { UserEventInstance } from '../setup';
|
|
3
|
-
|
|
3
|
+
interface CommonScrollToOptions {
|
|
4
|
+
contentSize?: {
|
|
5
|
+
height: number;
|
|
6
|
+
width: number;
|
|
7
|
+
};
|
|
8
|
+
layoutMeasurement?: {
|
|
9
|
+
height: number;
|
|
10
|
+
width: number;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface VerticalScrollToOptions extends CommonScrollToOptions {
|
|
4
14
|
y: number;
|
|
5
15
|
momentumY?: number;
|
|
6
16
|
x?: never;
|
|
7
17
|
momentumX?: never;
|
|
8
18
|
}
|
|
9
|
-
export interface HorizontalScrollToOptions {
|
|
19
|
+
export interface HorizontalScrollToOptions extends CommonScrollToOptions {
|
|
10
20
|
x: number;
|
|
11
21
|
momentumX?: number;
|
|
12
22
|
y?: never;
|
|
@@ -14,3 +24,4 @@ export interface HorizontalScrollToOptions {
|
|
|
14
24
|
}
|
|
15
25
|
export type ScrollToOptions = VerticalScrollToOptions | HorizontalScrollToOptions;
|
|
16
26
|
export declare function scrollTo(this: UserEventInstance, element: ReactTestInstance, options: ScrollToOptions): Promise<void>;
|
|
27
|
+
export {};
|
|
@@ -17,56 +17,57 @@ async function scrollTo(element, options) {
|
|
|
17
17
|
throw new _errors.ErrorWithStack(`scrollTo() works only with host "ScrollView" elements. Passed element has type "${element.type}".`, scrollTo);
|
|
18
18
|
}
|
|
19
19
|
ensureScrollViewDirection(element, options);
|
|
20
|
+
(0, _utils.dispatchEvent)(element, 'contentSizeChange', options.contentSize?.width ?? 0, options.contentSize?.height ?? 0);
|
|
20
21
|
const initialPosition = (0, _state.getElementScrollOffset)(element);
|
|
21
22
|
const dragSteps = (0, _utils2.createScrollSteps)({
|
|
22
23
|
y: options.y,
|
|
23
24
|
x: options.x
|
|
24
25
|
}, initialPosition, _utils2.linearInterpolator);
|
|
25
|
-
await emitDragScrollEvents(this.config, element, dragSteps);
|
|
26
|
+
await emitDragScrollEvents(this.config, element, dragSteps, options);
|
|
26
27
|
const momentumStart = dragSteps.at(-1) ?? initialPosition;
|
|
27
28
|
const momentumSteps = (0, _utils2.createScrollSteps)({
|
|
28
29
|
y: options.momentumY,
|
|
29
30
|
x: options.momentumX
|
|
30
31
|
}, momentumStart, _utils2.inertialInterpolator);
|
|
31
|
-
await emitMomentumScrollEvents(this.config, element, momentumSteps);
|
|
32
|
+
await emitMomentumScrollEvents(this.config, element, momentumSteps, options);
|
|
32
33
|
const finalPosition = momentumSteps.at(-1) ?? dragSteps.at(-1) ?? initialPosition;
|
|
33
34
|
(0, _state.setElementScrollOffset)(element, finalPosition);
|
|
34
35
|
}
|
|
35
|
-
async function emitDragScrollEvents(config, element, scrollSteps) {
|
|
36
|
+
async function emitDragScrollEvents(config, element, scrollSteps, scrollOptions) {
|
|
36
37
|
if (scrollSteps.length === 0) {
|
|
37
38
|
return;
|
|
38
39
|
}
|
|
39
40
|
await (0, _utils.wait)(config);
|
|
40
|
-
(0, _utils.dispatchEvent)(element, 'scrollBeginDrag', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[0]));
|
|
41
|
+
(0, _utils.dispatchEvent)(element, 'scrollBeginDrag', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[0], scrollOptions));
|
|
41
42
|
|
|
42
43
|
// Note: experimentally, in case of drag scroll the last scroll step
|
|
43
44
|
// will not trigger `scroll` event.
|
|
44
45
|
// See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events
|
|
45
46
|
for (let i = 1; i < scrollSteps.length - 1; i += 1) {
|
|
46
47
|
await (0, _utils.wait)(config);
|
|
47
|
-
(0, _utils.dispatchEvent)(element, 'scroll', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[i]));
|
|
48
|
+
(0, _utils.dispatchEvent)(element, 'scroll', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[i], scrollOptions));
|
|
48
49
|
}
|
|
49
50
|
await (0, _utils.wait)(config);
|
|
50
51
|
const lastStep = scrollSteps.at(-1);
|
|
51
|
-
(0, _utils.dispatchEvent)(element, 'scrollEndDrag', _eventBuilder.EventBuilder.ScrollView.scroll(lastStep));
|
|
52
|
+
(0, _utils.dispatchEvent)(element, 'scrollEndDrag', _eventBuilder.EventBuilder.ScrollView.scroll(lastStep, scrollOptions));
|
|
52
53
|
}
|
|
53
|
-
async function emitMomentumScrollEvents(config, element, scrollSteps) {
|
|
54
|
+
async function emitMomentumScrollEvents(config, element, scrollSteps, scrollOptions) {
|
|
54
55
|
if (scrollSteps.length === 0) {
|
|
55
56
|
return;
|
|
56
57
|
}
|
|
57
58
|
await (0, _utils.wait)(config);
|
|
58
|
-
(0, _utils.dispatchEvent)(element, 'momentumScrollBegin', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[0]));
|
|
59
|
+
(0, _utils.dispatchEvent)(element, 'momentumScrollBegin', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[0], scrollOptions));
|
|
59
60
|
|
|
60
61
|
// Note: experimentally, in case of momentum scroll the last scroll step
|
|
61
62
|
// will trigger `scroll` event.
|
|
62
63
|
// See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events
|
|
63
64
|
for (let i = 1; i < scrollSteps.length; i += 1) {
|
|
64
65
|
await (0, _utils.wait)(config);
|
|
65
|
-
(0, _utils.dispatchEvent)(element, 'scroll', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[i]));
|
|
66
|
+
(0, _utils.dispatchEvent)(element, 'scroll', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[i], scrollOptions));
|
|
66
67
|
}
|
|
67
68
|
await (0, _utils.wait)(config);
|
|
68
69
|
const lastStep = scrollSteps.at(-1);
|
|
69
|
-
(0, _utils.dispatchEvent)(element, 'momentumScrollEnd', _eventBuilder.EventBuilder.ScrollView.scroll(lastStep));
|
|
70
|
+
(0, _utils.dispatchEvent)(element, 'momentumScrollEnd', _eventBuilder.EventBuilder.ScrollView.scroll(lastStep, scrollOptions));
|
|
70
71
|
}
|
|
71
72
|
function ensureScrollViewDirection(element, options) {
|
|
72
73
|
const isVerticalScrollView = element.props.horizontal !== true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroll-to.js","names":["_jestMatcherUtils","require","_eventBuilder","_errors","_hostComponentNames","_object","_utils","_utils2","_state","scrollTo","element","options","isHostScrollView","ErrorWithStack","type","ensureScrollViewDirection","initialPosition","getElementScrollOffset","dragSteps","createScrollSteps","y","x","linearInterpolator","emitDragScrollEvents","config","momentumStart","at","momentumSteps","momentumY","momentumX","inertialInterpolator","emitMomentumScrollEvents","finalPosition","setElementScrollOffset","scrollSteps","length","wait","dispatchEvent","EventBuilder","ScrollView","scroll","i","lastStep","isVerticalScrollView","props","horizontal","hasHorizontalScrollOptions","undefined","stringify","pick","hasVerticalScrollOptions"],"sources":["../../../src/user-event/scroll/scroll-to.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { stringify } from 'jest-matcher-utils';\nimport { UserEventConfig, UserEventInstance } from '../setup';\nimport { EventBuilder } from '../event-builder';\nimport { ErrorWithStack } from '../../helpers/errors';\nimport { isHostScrollView } from '../../helpers/host-component-names';\nimport { pick } from '../../helpers/object';\nimport { dispatchEvent, wait } from '../utils';\nimport { ContentOffset } from '../event-builder/scroll-view';\nimport {\n createScrollSteps,\n inertialInterpolator,\n linearInterpolator,\n} from './utils';\nimport { getElementScrollOffset, setElementScrollOffset } from './state';\n\nexport interface VerticalScrollToOptions {\n y: number;\n momentumY?: number;\n\n // Vertical scroll should not contain horizontal scroll part.\n x?: never;\n momentumX?: never;\n}\n\nexport interface HorizontalScrollToOptions {\n x: number;\n momentumX?: number;\n\n // Horizontal scroll should not contain vertical scroll part.\n y?: never;\n momentumY?: never;\n}\n\nexport type ScrollToOptions =\n | VerticalScrollToOptions\n | HorizontalScrollToOptions;\n\nexport async function scrollTo(\n this: UserEventInstance,\n element: ReactTestInstance,\n options: ScrollToOptions\n): Promise<void> {\n if (!isHostScrollView(element)) {\n throw new ErrorWithStack(\n `scrollTo() works only with host \"ScrollView\" elements. Passed element has type \"${element.type}\".`,\n scrollTo\n );\n }\n\n ensureScrollViewDirection(element, options);\n\n const initialPosition = getElementScrollOffset(element);\n const dragSteps = createScrollSteps(\n { y: options.y, x: options.x },\n initialPosition,\n linearInterpolator\n );\n await emitDragScrollEvents(this.config, element, dragSteps);\n\n const momentumStart = dragSteps.at(-1) ?? initialPosition;\n const momentumSteps = createScrollSteps(\n { y: options.momentumY, x: options.momentumX },\n momentumStart,\n inertialInterpolator\n );\n await emitMomentumScrollEvents(this.config, element, momentumSteps);\n\n const finalPosition =\n momentumSteps.at(-1) ?? dragSteps.at(-1) ?? initialPosition;\n setElementScrollOffset(element, finalPosition);\n}\n\nasync function emitDragScrollEvents(\n config: UserEventConfig,\n element: ReactTestInstance,\n scrollSteps: ContentOffset[]\n) {\n if (scrollSteps.length === 0) {\n return;\n }\n\n await wait(config);\n dispatchEvent(\n element,\n 'scrollBeginDrag',\n EventBuilder.ScrollView.scroll(scrollSteps[0])\n );\n\n // Note: experimentally, in case of drag scroll the last scroll step\n // will not trigger `scroll` event.\n // See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events\n for (let i = 1; i < scrollSteps.length - 1; i += 1) {\n await wait(config);\n dispatchEvent(\n element,\n 'scroll',\n EventBuilder.ScrollView.scroll(scrollSteps[i])\n );\n }\n\n await wait(config);\n const lastStep = scrollSteps.at(-1);\n dispatchEvent(\n element,\n 'scrollEndDrag',\n EventBuilder.ScrollView.scroll(lastStep)\n );\n}\n\nasync function emitMomentumScrollEvents(\n config: UserEventConfig,\n element: ReactTestInstance,\n scrollSteps: ContentOffset[]\n) {\n if (scrollSteps.length === 0) {\n return;\n }\n\n await wait(config);\n dispatchEvent(\n element,\n 'momentumScrollBegin',\n EventBuilder.ScrollView.scroll(scrollSteps[0])\n );\n\n // Note: experimentally, in case of momentum scroll the last scroll step\n // will trigger `scroll` event.\n // See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events\n for (let i = 1; i < scrollSteps.length; i += 1) {\n await wait(config);\n dispatchEvent(\n element,\n 'scroll',\n EventBuilder.ScrollView.scroll(scrollSteps[i])\n );\n }\n\n await wait(config);\n const lastStep = scrollSteps.at(-1);\n dispatchEvent(\n element,\n 'momentumScrollEnd',\n EventBuilder.ScrollView.scroll(lastStep)\n );\n}\n\nfunction ensureScrollViewDirection(\n element: ReactTestInstance,\n options: ScrollToOptions\n) {\n const isVerticalScrollView = element.props.horizontal !== true;\n\n const hasHorizontalScrollOptions =\n options.x !== undefined || options.momentumX !== undefined;\n if (isVerticalScrollView && hasHorizontalScrollOptions) {\n throw new ErrorWithStack(\n `scrollTo() expected only vertical scroll options: \"y\" and \"momentumY\" for vertical \"ScrollView\" element but received ${stringify(\n pick(options, ['x', 'momentumX'])\n )}`,\n scrollTo\n );\n }\n\n const hasVerticalScrollOptions =\n options.y !== undefined || options.momentumY !== undefined;\n if (!isVerticalScrollView && hasVerticalScrollOptions) {\n throw new ErrorWithStack(\n `scrollTo() expected only horizontal scroll options: \"x\" and \"momentumX\" for horizontal \"ScrollView\" element but received ${stringify(\n pick(options, ['y', 'momentumY'])\n )}`,\n scrollTo\n );\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AAEA,IAAAM,OAAA,GAAAN,OAAA;AAKA,IAAAO,MAAA,GAAAP,OAAA;AAwBO,eAAeQ,QAAQA,CAE5BC,OAA0B,EAC1BC,OAAwB,EACT;EACf,IAAI,CAAC,IAAAC,oCAAgB,EAACF,OAAO,CAAC,EAAE;IAC9B,MAAM,IAAIG,sBAAc,CACrB,mFAAkFH,OAAO,CAACI,IAAK,IAAG,EACnGL,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ACnC,IAAAW,oBAAa,EACX3B,OAAO,EACP,mBAAmB,EACnB4B,0BAAY,CAACC,UAAU,CAACC,MAAM,CAACE,QAAQ,CACzC,CAAC;AACH;AAEA,SAAS3B,yBAAyBA,CAChCL,OAA0B,EAC1BC,OAAwB,EACxB;EACA,MAAMgC,oBAAoB,GAAGjC,OAAO,CAACkC,KAAK,CAACC,UAAU,KAAK,IAAI;EAE9D,MAAMC,0BAA0B,GAC9BnC,OAAO,CAACU,CAAC,KAAK0B,SAAS,IAAIpC,OAAO,CAACkB,SAAS,KAAKkB,SAAS;EAC5D,IAAIJ,oBAAoB,IAAIG,0BAA0B,EAAE;IACtD,MAAM,IAAIjC,sBAAc,CACrB,wHAAuH,IAAAmC,2BAAS,EAC/H,IAAAC,YAAI,EAACtC,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,CAClC,CAAE,EAAC,EACHF,QACF,CAAC;EACH;EAEA,MAAMyC,wBAAwB,GAC5BvC,OAAO,CAACS,CAAC,KAAK2B,SAAS,IAAIpC,OAAO,CAACiB,SAAS,KAAKmB,SAAS;EAC5D,IAAI,CAACJ,oBAAoB,IAAIO,wBAAwB,EAAE;IACrD,MAAM,IAAIrC,sBAAc,CACrB,4HAA2H,IAAAmC,2BAAS,EACnI,IAAAC,YAAI,EAACtC,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,CAClC,CAAE,EAAC,EACHF,QACF,CAAC;EACH;AACF"}
|
|
1
|
+
{"version":3,"file":"scroll-to.js","names":["_jestMatcherUtils","require","_eventBuilder","_errors","_hostComponentNames","_object","_utils","_utils2","_state","scrollTo","element","options","isHostScrollView","ErrorWithStack","type","ensureScrollViewDirection","dispatchEvent","contentSize","width","height","initialPosition","getElementScrollOffset","dragSteps","createScrollSteps","y","x","linearInterpolator","emitDragScrollEvents","config","momentumStart","at","momentumSteps","momentumY","momentumX","inertialInterpolator","emitMomentumScrollEvents","finalPosition","setElementScrollOffset","scrollSteps","scrollOptions","length","wait","EventBuilder","ScrollView","scroll","i","lastStep","isVerticalScrollView","props","horizontal","hasHorizontalScrollOptions","undefined","stringify","pick","hasVerticalScrollOptions"],"sources":["../../../src/user-event/scroll/scroll-to.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { stringify } from 'jest-matcher-utils';\nimport { UserEventConfig, UserEventInstance } from '../setup';\nimport { EventBuilder } from '../event-builder';\nimport { ErrorWithStack } from '../../helpers/errors';\nimport { isHostScrollView } from '../../helpers/host-component-names';\nimport { pick } from '../../helpers/object';\nimport { ContentOffset } from '../event-builder/scroll-view';\nimport { dispatchEvent, wait } from '../utils';\nimport {\n createScrollSteps,\n inertialInterpolator,\n linearInterpolator,\n} from './utils';\nimport { getElementScrollOffset, setElementScrollOffset } from './state';\n\ninterface CommonScrollToOptions {\n contentSize?: {\n height: number;\n width: number;\n };\n layoutMeasurement?: {\n height: number;\n width: number;\n };\n}\n\nexport interface VerticalScrollToOptions extends CommonScrollToOptions {\n y: number;\n momentumY?: number;\n\n // Vertical scroll should not contain horizontal scroll part.\n x?: never;\n momentumX?: never;\n}\n\nexport interface HorizontalScrollToOptions extends CommonScrollToOptions {\n x: number;\n momentumX?: number;\n\n // Horizontal scroll should not contain vertical scroll part.\n y?: never;\n momentumY?: never;\n}\n\nexport type ScrollToOptions =\n | VerticalScrollToOptions\n | HorizontalScrollToOptions;\n\nexport async function scrollTo(\n this: UserEventInstance,\n element: ReactTestInstance,\n options: ScrollToOptions\n): Promise<void> {\n if (!isHostScrollView(element)) {\n throw new ErrorWithStack(\n `scrollTo() works only with host \"ScrollView\" elements. Passed element has type \"${element.type}\".`,\n scrollTo\n );\n }\n\n ensureScrollViewDirection(element, options);\n\n dispatchEvent(\n element,\n 'contentSizeChange',\n options.contentSize?.width ?? 0,\n options.contentSize?.height ?? 0\n );\n\n const initialPosition = getElementScrollOffset(element);\n const dragSteps = createScrollSteps(\n { y: options.y, x: options.x },\n initialPosition,\n linearInterpolator\n );\n await emitDragScrollEvents(this.config, element, dragSteps, options);\n\n const momentumStart = dragSteps.at(-1) ?? initialPosition;\n const momentumSteps = createScrollSteps(\n { y: options.momentumY, x: options.momentumX },\n momentumStart,\n inertialInterpolator\n );\n await emitMomentumScrollEvents(this.config, element, momentumSteps, options);\n\n const finalPosition =\n momentumSteps.at(-1) ?? dragSteps.at(-1) ?? initialPosition;\n setElementScrollOffset(element, finalPosition);\n}\n\nasync function emitDragScrollEvents(\n config: UserEventConfig,\n element: ReactTestInstance,\n scrollSteps: ContentOffset[],\n scrollOptions: ScrollToOptions\n) {\n if (scrollSteps.length === 0) {\n return;\n }\n\n await wait(config);\n dispatchEvent(\n element,\n 'scrollBeginDrag',\n EventBuilder.ScrollView.scroll(scrollSteps[0], scrollOptions)\n );\n\n // Note: experimentally, in case of drag scroll the last scroll step\n // will not trigger `scroll` event.\n // See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events\n for (let i = 1; i < scrollSteps.length - 1; i += 1) {\n await wait(config);\n dispatchEvent(\n element,\n 'scroll',\n EventBuilder.ScrollView.scroll(scrollSteps[i], scrollOptions)\n );\n }\n\n await wait(config);\n const lastStep = scrollSteps.at(-1);\n dispatchEvent(\n element,\n 'scrollEndDrag',\n EventBuilder.ScrollView.scroll(lastStep, scrollOptions)\n );\n}\n\nasync function emitMomentumScrollEvents(\n config: UserEventConfig,\n element: ReactTestInstance,\n scrollSteps: ContentOffset[],\n scrollOptions: ScrollToOptions\n) {\n if (scrollSteps.length === 0) {\n return;\n }\n\n await wait(config);\n dispatchEvent(\n element,\n 'momentumScrollBegin',\n EventBuilder.ScrollView.scroll(scrollSteps[0], scrollOptions)\n );\n\n // Note: experimentally, in case of momentum scroll the last scroll step\n // will trigger `scroll` event.\n // See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events\n for (let i = 1; i < scrollSteps.length; i += 1) {\n await wait(config);\n dispatchEvent(\n element,\n 'scroll',\n EventBuilder.ScrollView.scroll(scrollSteps[i], scrollOptions)\n );\n }\n\n await wait(config);\n const lastStep = scrollSteps.at(-1);\n dispatchEvent(\n element,\n 'momentumScrollEnd',\n EventBuilder.ScrollView.scroll(lastStep, scrollOptions)\n );\n}\n\nfunction ensureScrollViewDirection(\n element: ReactTestInstance,\n options: ScrollToOptions\n) {\n const isVerticalScrollView = element.props.horizontal !== true;\n\n const hasHorizontalScrollOptions =\n options.x !== undefined || options.momentumX !== undefined;\n if (isVerticalScrollView && hasHorizontalScrollOptions) {\n throw new ErrorWithStack(\n `scrollTo() expected only vertical scroll options: \"y\" and \"momentumY\" for vertical \"ScrollView\" element but received ${stringify(\n pick(options, ['x', 'momentumX'])\n )}`,\n scrollTo\n );\n }\n\n const hasVerticalScrollOptions =\n options.y !== undefined || options.momentumY !== undefined;\n if (!isVerticalScrollView && hasVerticalScrollOptions) {\n throw new ErrorWithStack(\n `scrollTo() expected only horizontal scroll options: \"x\" and \"momentumX\" for horizontal \"ScrollView\" element but received ${stringify(\n pick(options, ['y', 'momentumY'])\n )}`,\n scrollTo\n );\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,OAAA,GAAAN,OAAA;AAKA,IAAAO,MAAA,GAAAP,OAAA;AAmCO,eAAeQ,QAAQA,CAE5BC,OAA0B,EAC1BC,OAAwB,EACT;EACf,IAAI,CAAC,IAAAC,oCAAgB,EAACF,OAAO,CAAC,EAAE;IAC9B,MAAM,IAAIG,sBAAc,CACrB,mFAAkFH,OAAO,CAACI,IAAK,IAAG,EACnGL,QACF,CAAC;EACH;EAEAM,yBAAyB,CAACL,OAAO,EAAEC,OAAO,CAAC;EAE3C,IAAAK,oBAAa,EACXN,OAAO,EACP,mBAAmB,EACnBC,OAAO,CAACM,WAAW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EN,aAAa,CAC9D,CAAC;EACH;EAEA,MAAM,IAAAE,WAAI,EAACb,MAAM,CAAC;EAClB,MAAMkB,QAAQ,GAAGR,WAAW,CAACR,EAAE,CAAC,CAAC,CAAC,CAAC;EACnC,IAAAd,oBAAa,EACXN,OAAO,EACP,mBAAmB,EACnBgC,0BAAY,CAACC,UAAU,CAACC,MAAM,CAACE,QAAQ,EAAEP,aAAa,CACxD,CAAC;AACH;AAEA,SAASxB,yBAAyBA,CAChCL,OAA0B,EAC1BC,OAAwB,EACxB;EACA,MAAMoC,oBAAoB,GAAGrC,OAAO,CAACsC,KAAK,CAACC,UAAU,KAAK,IAAI;EAE9D,MAAMC,0BAA0B,GAC9BvC,OAAO,CAACc,CAAC,KAAK0B,SAAS,IAAIxC,OAAO,CAACsB,SAAS,KAAKkB,SAAS;EAC5D,IAAIJ,oBAAoB,IAAIG,0BAA0B,EAAE;IACtD,MAAM,IAAIrC,sBAAc,CACrB,wHAAuH,IAAAuC,2BAAS,EAC/H,IAAAC,YAAI,EAAC1C,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,CAClC,CAAE,EAAC,EACHF,QACF,CAAC;EACH;EAEA,MAAM6C,wBAAwB,GAC5B3C,OAAO,CAACa,CAAC,KAAK2B,SAAS,IAAIxC,OAAO,CAACqB,SAAS,KAAKmB,SAAS;EAC5D,IAAI,CAACJ,oBAAoB,IAAIO,wBAAwB,EAAE;IACrD,MAAM,IAAIzC,sBAAc,CACrB,4HAA2H,IAAAuC,2BAAS,EACnI,IAAAC,YAAI,EAAC1C,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,CAClC,CAAE,EAAC,EACHF,QACF,CAAC;EACH;AACF"}
|
|
@@ -4,6 +4,6 @@ import { ReactTestInstance } from 'react-test-renderer';
|
|
|
4
4
|
*
|
|
5
5
|
* @param element element trigger event on
|
|
6
6
|
* @param eventName name of the event
|
|
7
|
-
* @param event event payload
|
|
7
|
+
* @param event event payload(s)
|
|
8
8
|
*/
|
|
9
|
-
export declare function dispatchEvent(element: ReactTestInstance, eventName: string, event: unknown): void;
|
|
9
|
+
export declare function dispatchEvent(element: ReactTestInstance, eventName: string, ...event: unknown[]): void;
|
|
@@ -11,9 +11,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
11
11
|
*
|
|
12
12
|
* @param element element trigger event on
|
|
13
13
|
* @param eventName name of the event
|
|
14
|
-
* @param event event payload
|
|
14
|
+
* @param event event payload(s)
|
|
15
15
|
*/
|
|
16
|
-
function dispatchEvent(element, eventName, event) {
|
|
16
|
+
function dispatchEvent(element, eventName, ...event) {
|
|
17
17
|
const handler = getEventHandler(element, eventName);
|
|
18
18
|
if (!handler) {
|
|
19
19
|
return;
|
|
@@ -21,7 +21,7 @@ function dispatchEvent(element, eventName, event) {
|
|
|
21
21
|
|
|
22
22
|
// This will be called synchronously.
|
|
23
23
|
void (0, _act.default)(() => {
|
|
24
|
-
handler(event);
|
|
24
|
+
handler(...event);
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
function getEventHandler(element, eventName) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch-event.js","names":["_act","_interopRequireDefault","require","obj","__esModule","default","dispatchEvent","element","eventName","event","handler","getEventHandler","act","handleName","getEventHandlerName","handle","props","undefined","charAt","toUpperCase","slice"],"sources":["../../../src/user-event/utils/dispatch-event.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport act from '../../act';\n\n/**\n * Basic dispatch event function used by User Event module.\n *\n * @param element element trigger event on\n * @param eventName name of the event\n * @param event event payload\n */\nexport function dispatchEvent(\n element: ReactTestInstance,\n eventName: string,\n event: unknown\n) {\n const handler = getEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n // This will be called synchronously.\n void act(() => {\n handler(event);\n });\n}\n\nfunction getEventHandler(element: ReactTestInstance, eventName: string) {\n const handleName = getEventHandlerName(eventName);\n const handle = element.props[handleName] as unknown;\n if (typeof handle !== 'function') {\n return undefined;\n }\n\n return handle;\n}\n\nfunction getEventHandlerName(eventName: string) {\n return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\n}\n"],"mappings":";;;;;;AACA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA4B,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,aAAaA,CAC3BC,OAA0B,EAC1BC,SAAiB,
|
|
1
|
+
{"version":3,"file":"dispatch-event.js","names":["_act","_interopRequireDefault","require","obj","__esModule","default","dispatchEvent","element","eventName","event","handler","getEventHandler","act","handleName","getEventHandlerName","handle","props","undefined","charAt","toUpperCase","slice"],"sources":["../../../src/user-event/utils/dispatch-event.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport act from '../../act';\n\n/**\n * Basic dispatch event function used by User Event module.\n *\n * @param element element trigger event on\n * @param eventName name of the event\n * @param event event payload(s)\n */\nexport function dispatchEvent(\n element: ReactTestInstance,\n eventName: string,\n ...event: unknown[]\n) {\n const handler = getEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n // This will be called synchronously.\n void act(() => {\n handler(...event);\n });\n}\n\nfunction getEventHandler(element: ReactTestInstance, eventName: string) {\n const handleName = getEventHandlerName(eventName);\n const handle = element.props[handleName] as unknown;\n if (typeof handle !== 'function') {\n return undefined;\n }\n\n return handle;\n}\n\nfunction getEventHandlerName(eventName: string) {\n return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\n}\n"],"mappings":";;;;;;AACA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA4B,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,aAAaA,CAC3BC,OAA0B,EAC1BC,SAAiB,EACjB,GAAGC,KAAgB,EACnB;EACA,MAAMC,OAAO,GAAGC,eAAe,CAACJ,OAAO,EAAEC,SAAS,CAAC;EACnD,IAAI,CAACE,OAAO,EAAE;IACZ;EACF;;EAEA;EACA,KAAK,IAAAE,YAAG,EAAC,MAAM;IACbF,OAAO,CAAC,GAAGD,KAAK,CAAC;EACnB,CAAC,CAAC;AACJ;AAEA,SAASE,eAAeA,CAACJ,OAA0B,EAAEC,SAAiB,EAAE;EACtE,MAAMK,UAAU,GAAGC,mBAAmB,CAACN,SAAS,CAAC;EACjD,MAAMO,MAAM,GAAGR,OAAO,CAACS,KAAK,CAACH,UAAU,CAAY;EACnD,IAAI,OAAOE,MAAM,KAAK,UAAU,EAAE;IAChC,OAAOE,SAAS;EAClB;EAEA,OAAOF,MAAM;AACf;AAEA,SAASD,mBAAmBA,CAACN,SAAiB,EAAE;EAC9C,OAAQ,KAAIA,SAAS,CAACU,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAE,GAAEX,SAAS,CAACY,KAAK,CAAC,CAAC,CAAE,EAAC;AACtE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testing-library/react-native",
|
|
3
|
-
"version": "12.4.
|
|
3
|
+
"version": "12.4.3",
|
|
4
4
|
"description": "Simple and complete React Native testing utilities that encourage good testing practices.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -23,6 +23,25 @@
|
|
|
23
23
|
"test",
|
|
24
24
|
"integration"
|
|
25
25
|
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"clean": "del build",
|
|
28
|
+
"test": "jest",
|
|
29
|
+
"test:ci": "jest --maxWorkers=2 --collectCoverage=true --coverage-provider=v8",
|
|
30
|
+
"test:react-17": "scripts/test_react_17",
|
|
31
|
+
"typecheck": "tsc",
|
|
32
|
+
"flow": "flow",
|
|
33
|
+
"copy-flowtypes": "cp typings/index.flow.js build",
|
|
34
|
+
"lint": "eslint src --cache",
|
|
35
|
+
"validate": "yarn lint && yarn typecheck && yarn test",
|
|
36
|
+
"build:js": "babel src --out-dir build --extensions \".js,.ts,.jsx,.tsx\" --source-maps --ignore \"**/__tests__/**\"",
|
|
37
|
+
"build:js:watch": "yarn build:js --watch",
|
|
38
|
+
"build:ts": "tsc --build tsconfig.release.json",
|
|
39
|
+
"build:ts:watch": "yarn build:ts --watch --preserveWatchOutput",
|
|
40
|
+
"build": "yarn clean && yarn build:js && yarn build:ts && yarn copy-flowtypes",
|
|
41
|
+
"prepare": "yarn build",
|
|
42
|
+
"prepublish": "yarn build",
|
|
43
|
+
"publish": "release-it"
|
|
44
|
+
},
|
|
26
45
|
"files": [
|
|
27
46
|
"build/",
|
|
28
47
|
"jest-preset/",
|
|
@@ -33,6 +52,22 @@
|
|
|
33
52
|
"dont-cleanup-after-each.js",
|
|
34
53
|
"typings/index.flow.js"
|
|
35
54
|
],
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"jest-matcher-utils": "^29.7.0",
|
|
57
|
+
"pretty-format": "^29.7.0",
|
|
58
|
+
"redent": "^3.0.0"
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"jest": ">=28.0.0",
|
|
62
|
+
"react": ">=16.8.0",
|
|
63
|
+
"react-native": ">=0.59",
|
|
64
|
+
"react-test-renderer": ">=16.8.0"
|
|
65
|
+
},
|
|
66
|
+
"peerDependenciesMeta": {
|
|
67
|
+
"jest": {
|
|
68
|
+
"optional": true
|
|
69
|
+
}
|
|
70
|
+
},
|
|
36
71
|
"devDependencies": {
|
|
37
72
|
"@babel/cli": "^7.23.4",
|
|
38
73
|
"@babel/core": "^7.23.3",
|
|
@@ -42,6 +77,7 @@
|
|
|
42
77
|
"@babel/preset-react": "^7.23.3",
|
|
43
78
|
"@babel/preset-typescript": "^7.23.3",
|
|
44
79
|
"@callstack/eslint-config": "^14.1.0",
|
|
80
|
+
"@release-it/conventional-changelog": "^8.0.1",
|
|
45
81
|
"@relmify/jest-serializer-strip-ansi": "^1.0.2",
|
|
46
82
|
"@types/jest": "^29.5.10",
|
|
47
83
|
"@types/react": "^18.2.38",
|
|
@@ -57,42 +93,12 @@
|
|
|
57
93
|
"react": "18.2.0",
|
|
58
94
|
"react-native": "0.72.7",
|
|
59
95
|
"react-test-renderer": "18.2.0",
|
|
96
|
+
"release-it": "^17.0.1",
|
|
60
97
|
"strip-ansi": "^6.0.1",
|
|
61
98
|
"typescript": "^5.3.2"
|
|
62
99
|
},
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"pretty-format": "^29.7.0",
|
|
66
|
-
"redent": "^3.0.0"
|
|
67
|
-
},
|
|
68
|
-
"peerDependencies": {
|
|
69
|
-
"jest": ">=28.0.0",
|
|
70
|
-
"react": ">=16.8.0",
|
|
71
|
-
"react-native": ">=0.59",
|
|
72
|
-
"react-test-renderer": ">=16.8.0"
|
|
73
|
-
},
|
|
74
|
-
"peerDependenciesMeta": {
|
|
75
|
-
"jest": {
|
|
76
|
-
"optional": true
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
"scripts": {
|
|
80
|
-
"clean": "del build",
|
|
81
|
-
"test": "jest",
|
|
82
|
-
"test:ci": "jest --maxWorkers=2 --collectCoverage=true --coverage-provider=v8",
|
|
83
|
-
"test:react-17": "scripts/test_react_17",
|
|
84
|
-
"typecheck": "tsc",
|
|
85
|
-
"flow": "flow",
|
|
86
|
-
"copy-flowtypes": "cp typings/index.flow.js build",
|
|
87
|
-
"lint": "eslint src --cache",
|
|
88
|
-
"validate": "yarn lint && yarn typecheck && yarn test",
|
|
89
|
-
"prepublish": "yarn build",
|
|
90
|
-
"build:js": "babel src --out-dir build --extensions \".js,.ts,.jsx,.tsx\" --source-maps --ignore \"**/__tests__/**\"",
|
|
91
|
-
"build:js:watch": "yarn build:js --watch",
|
|
92
|
-
"build:ts": "tsc --build tsconfig.release.json",
|
|
93
|
-
"build:ts:watch": "yarn build:ts --watch --preserveWatchOutput",
|
|
94
|
-
"build": "yarn clean && yarn build:js && yarn build:ts && yarn copy-flowtypes",
|
|
95
|
-
"prepare": "yarn build"
|
|
100
|
+
"publishConfig": {
|
|
101
|
+
"registry": "https://registry.npmjs.org"
|
|
96
102
|
},
|
|
97
103
|
"packageManager": "yarn@4.0.1"
|
|
98
|
-
}
|
|
104
|
+
}
|