-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathreact-native-gesture-handler.test.tsx
61 lines (50 loc) · 1.62 KB
/
react-native-gesture-handler.test.tsx
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
import 'react-native-gesture-handler/jestSetup.js';
import React from 'react';
import { View } from 'react-native';
import { Pressable } from 'react-native-gesture-handler';
import { fireEvent, render, screen, userEvent } from '..';
import { createEventLogger, getEventsNames } from '../test-utils';
test('fireEvent can invoke press events for RNGH Pressable', () => {
const onPress = jest.fn();
const onPressIn = jest.fn();
const onPressOut = jest.fn();
const onLongPress = jest.fn();
render(
<View>
<Pressable
testID="pressable"
onPress={onPress}
onPressIn={onPressIn}
onPressOut={onPressOut}
onLongPress={onLongPress}
/>
</View>,
);
const pressable = screen.getByTestId('pressable');
fireEvent.press(pressable);
expect(onPress).toHaveBeenCalled();
fireEvent(pressable, 'pressIn');
expect(onPressIn).toHaveBeenCalled();
fireEvent(pressable, 'pressOut');
expect(onPressOut).toHaveBeenCalled();
fireEvent(pressable, 'longPress');
expect(onLongPress).toHaveBeenCalled();
});
test('userEvent can invoke press events for RNGH Pressable', async () => {
const { events, logEvent } = createEventLogger();
const user = userEvent.setup();
render(
<View>
<Pressable
testID="pressable"
onPress={logEvent('press')}
onPressIn={logEvent('pressIn')}
onPressOut={logEvent('pressOut')}
onLongPress={logEvent('longPress')}
/>
</View>,
);
const pressable = screen.getByTestId('pressable');
await user.press(pressable);
expect(getEventsNames(events)).toEqual(['pressIn', 'pressOut', 'press']);
});