1
1
import React from 'react' ;
2
- import { Pressable , Text } from 'react-native' ;
3
- import { render , screen } from '../../../pure' ;
2
+ import { Pressable , Text , TouchableHighlight , TouchableOpacity } from 'react-native' ;
3
+ import { createEventLogger , getEventsNames } from '../../../test-utils' ;
4
+ import { render , screen } from '../../..' ;
4
5
import { userEvent } from '../..' ;
5
6
6
7
describe ( 'userEvent.longPress with real timers' , ( ) => {
@@ -9,6 +10,68 @@ describe('userEvent.longPress with real timers', () => {
9
10
jest . restoreAllMocks ( ) ;
10
11
} ) ;
11
12
13
+ test ( 'works on Pressable' , async ( ) => {
14
+ const { events, logEvent } = createEventLogger ( ) ;
15
+ const user = userEvent . setup ( ) ;
16
+
17
+ render (
18
+ < Pressable
19
+ onPress = { logEvent ( 'press' ) }
20
+ onPressIn = { logEvent ( 'pressIn' ) }
21
+ onPressOut = { logEvent ( 'pressOut' ) }
22
+ onLongPress = { logEvent ( 'longPress' ) }
23
+ testID = "pressable"
24
+ /> ,
25
+ ) ;
26
+
27
+ await user . longPress ( screen . getByTestId ( 'pressable' ) ) ;
28
+ expect ( getEventsNames ( events ) ) . toEqual ( [ 'pressIn' , 'longPress' , 'pressOut' ] ) ;
29
+ } ) ;
30
+
31
+ test ( 'works on TouchableOpacity' , async ( ) => {
32
+ const mockOnPress = jest . fn ( ) ;
33
+
34
+ render (
35
+ < TouchableOpacity onPress = { mockOnPress } >
36
+ < Text > press me</ Text >
37
+ </ TouchableOpacity > ,
38
+ ) ;
39
+
40
+ await userEvent . longPress ( screen . getByText ( 'press me' ) ) ;
41
+ expect ( mockOnPress ) . toHaveBeenCalled ( ) ;
42
+ } ) ;
43
+
44
+ test ( 'works on TouchableHighlight' , async ( ) => {
45
+ const mockOnPress = jest . fn ( ) ;
46
+
47
+ render (
48
+ < TouchableHighlight onPress = { mockOnPress } >
49
+ < Text > press me</ Text >
50
+ </ TouchableHighlight > ,
51
+ ) ;
52
+
53
+ await userEvent . longPress ( screen . getByText ( 'press me' ) ) ;
54
+ expect ( mockOnPress ) . toHaveBeenCalled ( ) ;
55
+ } ) ;
56
+
57
+ test ( 'works on Text' , async ( ) => {
58
+ const { events, logEvent } = createEventLogger ( ) ;
59
+
60
+ render (
61
+ < Text
62
+ onPress = { logEvent ( 'press' ) }
63
+ onPressIn = { logEvent ( 'pressIn' ) }
64
+ onPressOut = { logEvent ( 'pressOut' ) }
65
+ onLongPress = { logEvent ( 'longPress' ) }
66
+ >
67
+ press me
68
+ </ Text > ,
69
+ ) ;
70
+
71
+ await userEvent . longPress ( screen . getByText ( 'press me' ) ) ;
72
+ expect ( getEventsNames ( events ) ) . toEqual ( [ 'pressIn' , 'longPress' , 'pressOut' ] ) ;
73
+ } ) ;
74
+
12
75
test ( 'calls onLongPress if the delayLongPress is the default one' , async ( ) => {
13
76
const mockOnLongPress = jest . fn ( ) ;
14
77
const user = userEvent . setup ( ) ;
0 commit comments