-
Notifications
You must be signed in to change notification settings - Fork 278
Expand file tree
/
Copy pathreact-native-gesture-handler.test.tsx
More file actions
65 lines (53 loc) · 1.77 KB
/
react-native-gesture-handler.test.tsx
File metadata and controls
65 lines (53 loc) · 1.77 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
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/events';
test('fireEvent can invoke press events for RNGH Pressable', async () => {
const onPress = jest.fn();
const onPressIn = jest.fn();
const onPressOut = jest.fn();
const onLongPress = jest.fn();
await render(
<View>
<Pressable
testID="pressable"
onPress={onPress}
onPressIn={onPressIn}
onPressOut={onPressOut}
onLongPress={onLongPress}
/>
</View>,
);
const pressable = screen.getByTestId('pressable');
await fireEvent.press(pressable);
expect(onPress).toHaveBeenCalled();
await fireEvent(pressable, 'pressIn');
expect(onPressIn).toHaveBeenCalled();
await fireEvent(pressable, 'pressOut');
expect(onPressOut).toHaveBeenCalled();
await fireEvent(pressable, 'longPress');
expect(onLongPress).toHaveBeenCalled();
});
test('userEvent can invoke press events for RNGH Pressable', async () => {
const { events, logEvent } = createEventLogger();
const user = userEvent.setup();
await 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);
const eventSequence = getEventsNames(events).join(', ');
expect(
eventSequence === 'pressIn, pressOut, press' || eventSequence === 'pressIn, press, pressOut',
).toBe(true);
});