-
Notifications
You must be signed in to change notification settings - Fork 278
Expand file tree
/
Copy pathpull-to-refresh.test.tsx
More file actions
69 lines (58 loc) · 2.15 KB
/
pull-to-refresh.test.tsx
File metadata and controls
69 lines (58 loc) · 2.15 KB
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
import * as React from 'react';
import { FlatList, RefreshControl, ScrollView, SectionList, Text } from 'react-native';
import { render, screen, userEvent } from '../../..';
describe('pullToRefresh()', () => {
it('supports ScrollView', async () => {
const onRefreshMock = jest.fn();
render(
<ScrollView
testID="view"
refreshControl={<RefreshControl refreshing={false} onRefresh={onRefreshMock} />}
/>,
);
const user = userEvent.setup();
await user.pullToRefresh(screen.getByTestId('view'));
expect(onRefreshMock).toHaveBeenCalled();
});
it('supports FlatList', async () => {
const onRefreshMock = jest.fn();
render(
<FlatList
testID="view"
data={['A', 'B', 'C']}
renderItem={({ item }) => <Text>{item}</Text>}
refreshControl={<RefreshControl refreshing={false} onRefresh={onRefreshMock} />}
/>,
);
const user = userEvent.setup();
await user.pullToRefresh(screen.getByTestId('view'));
expect(onRefreshMock).toHaveBeenCalled();
});
it('supports SectionList', async () => {
const onRefreshMock = jest.fn();
render(
<SectionList
testID="view"
sections={[
{ title: 'Section 1', data: ['A', 'B', 'C'] },
{ title: 'Section 2', data: ['D', 'E', 'F'] },
]}
renderItem={({ item }) => <Text>{item}</Text>}
refreshControl={<RefreshControl refreshing={false} onRefresh={onRefreshMock} />}
/>,
);
const user = userEvent.setup();
await user.pullToRefresh(screen.getByTestId('view'));
expect(onRefreshMock).toHaveBeenCalled();
});
it('does not throw when RefreshControl is not set', async () => {
render(<ScrollView testID="view" />);
const user = userEvent.setup();
await expect(() => user.pullToRefresh(screen.getByTestId('view'))).not.toThrow();
});
it('does not throw when RefreshControl onRefresh is not set', async () => {
render(<ScrollView testID="view" refreshControl={<RefreshControl refreshing={false} />} />);
const user = userEvent.setup();
await expect(() => user.pullToRefresh(screen.getByTestId('view'))).not.toThrow();
});
});