-
Notifications
You must be signed in to change notification settings - Fork 278
Expand file tree
/
Copy pathpull-to-refresh.ts
More file actions
28 lines (24 loc) · 870 Bytes
/
pull-to-refresh.ts
File metadata and controls
28 lines (24 loc) · 870 Bytes
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
import type { ReactTestInstance } from 'react-test-renderer';
import act from '../../act';
import { ErrorWithStack } from '../../helpers/errors';
import { isHostScrollView } from '../../helpers/host-component-names';
import type { UserEventInstance } from '../setup';
export async function pullToRefresh(
this: UserEventInstance,
element: ReactTestInstance,
): Promise<void> {
if (!isHostScrollView(element)) {
throw new ErrorWithStack(
`pullToRefresh() works only with host "ScrollView" elements. Passed element has type "${element.type}".`,
pullToRefresh,
);
}
const refreshControl = element.props.refreshControl;
if (refreshControl == null || typeof refreshControl.props.onRefresh !== 'function') {
return;
}
// eslint-disable-next-line require-await
await act(async () => {
refreshControl.props.onRefresh();
});
}