File tree Expand file tree Collapse file tree 2 files changed +151
-4
lines changed
src/user-event/press/__tests__ Expand file tree Collapse file tree 2 files changed +151
-4
lines changed Original file line number Diff line number Diff line change @@ -2,24 +2,73 @@ import React from 'react';
2
2
import { Pressable , Text } from 'react-native' ;
3
3
import { render , screen } from '../../../pure' ;
4
4
import { userEvent } from '../..' ;
5
+ import { createEventLogger } from '../../../test-utils' ;
5
6
6
7
describe ( 'userEvent.longPress with fake timers' , ( ) => {
7
8
beforeEach ( ( ) => {
8
9
jest . useFakeTimers ( ) ;
10
+ jest . setSystemTime ( 0 ) ;
9
11
} ) ;
10
12
11
13
test ( 'calls onLongPress if the delayLongPress is the default one' , async ( ) => {
12
- const mockOnLongPress = jest . fn ( ) ;
14
+ const { logEvent , events } = createEventLogger ( ) ;
13
15
const user = userEvent . setup ( ) ;
14
16
15
17
render (
16
- < Pressable onLongPress = { mockOnLongPress } >
18
+ < Pressable onLongPress = { logEvent ( 'longPress' ) } >
17
19
< Text > press me</ Text >
18
20
</ Pressable >
19
21
) ;
20
22
await user . longPress ( screen . getByText ( 'press me' ) ) ;
21
23
22
- expect ( mockOnLongPress ) . toHaveBeenCalled ( ) ;
24
+ expect ( events ) . toMatchInlineSnapshot ( `
25
+ [
26
+ {
27
+ "name": "longPress",
28
+ "payload": {
29
+ "currentTarget": {
30
+ "measure": [MockFunction] {
31
+ "calls": [
32
+ [
33
+ [Function],
34
+ ],
35
+ [
36
+ [Function],
37
+ ],
38
+ ],
39
+ "results": [
40
+ {
41
+ "type": "return",
42
+ "value": undefined,
43
+ },
44
+ {
45
+ "type": "return",
46
+ "value": undefined,
47
+ },
48
+ ],
49
+ },
50
+ },
51
+ "dispatchConfig": {
52
+ "registrationName": "onResponderGrant",
53
+ },
54
+ "nativeEvent": {
55
+ "timestamp": 500,
56
+ },
57
+ "persist": [MockFunction] {
58
+ "calls": [
59
+ [],
60
+ ],
61
+ "results": [
62
+ {
63
+ "type": "return",
64
+ "value": undefined,
65
+ },
66
+ ],
67
+ },
68
+ },
69
+ },
70
+ ]
71
+ ` ) ;
23
72
} ) ;
24
73
25
74
test ( 'calls onLongPress when duration is greater than specified onLongPressDelay' , async ( ) => {
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import { userEvent } from '../..';
14
14
describe ( 'userEvent.press with fake timers' , ( ) => {
15
15
beforeEach ( ( ) => {
16
16
jest . useFakeTimers ( ) ;
17
+ jest . setSystemTime ( 0 ) ;
17
18
} ) ;
18
19
19
20
test ( 'calls onPressIn, onPress and onPressOut prop of touchable' , async ( ) => {
@@ -30,7 +31,104 @@ describe('userEvent.press with fake timers', () => {
30
31
) ;
31
32
await user . press ( screen . getByTestId ( 'pressable' ) ) ;
32
33
33
- expect ( getEventsName ( events ) ) . toEqual ( [ 'pressIn' , 'press' , 'pressOut' ] ) ;
34
+ expect ( events ) . toMatchInlineSnapshot ( `
35
+ [
36
+ {
37
+ "name": "pressIn",
38
+ "payload": {
39
+ "currentTarget": {
40
+ "measure": [MockFunction] {
41
+ "calls": [
42
+ [
43
+ [Function],
44
+ ],
45
+ [
46
+ [Function],
47
+ ],
48
+ ],
49
+ "results": [
50
+ {
51
+ "type": "return",
52
+ "value": undefined,
53
+ },
54
+ {
55
+ "type": "return",
56
+ "value": undefined,
57
+ },
58
+ ],
59
+ },
60
+ },
61
+ "dispatchConfig": {
62
+ "registrationName": "onResponderGrant",
63
+ },
64
+ "nativeEvent": {
65
+ "timestamp": 0,
66
+ },
67
+ "persist": [MockFunction] {
68
+ "calls": [
69
+ [],
70
+ ],
71
+ "results": [
72
+ {
73
+ "type": "return",
74
+ "value": undefined,
75
+ },
76
+ ],
77
+ },
78
+ },
79
+ },
80
+ {
81
+ "name": "press",
82
+ "payload": {
83
+ "currentTarget": {
84
+ "measure": [MockFunction],
85
+ },
86
+ "dispatchConfig": {
87
+ "registrationName": "onResponderRelease",
88
+ },
89
+ "nativeEvent": {
90
+ "timestamp": 0,
91
+ },
92
+ "persist": [MockFunction] {
93
+ "calls": [
94
+ [],
95
+ ],
96
+ "results": [
97
+ {
98
+ "type": "return",
99
+ "value": undefined,
100
+ },
101
+ ],
102
+ },
103
+ },
104
+ },
105
+ {
106
+ "name": "pressOut",
107
+ "payload": {
108
+ "currentTarget": {
109
+ "measure": [MockFunction],
110
+ },
111
+ "dispatchConfig": {
112
+ "registrationName": "onResponderRelease",
113
+ },
114
+ "nativeEvent": {
115
+ "timestamp": 0,
116
+ },
117
+ "persist": [MockFunction] {
118
+ "calls": [
119
+ [],
120
+ ],
121
+ "results": [
122
+ {
123
+ "type": "return",
124
+ "value": undefined,
125
+ },
126
+ ],
127
+ },
128
+ },
129
+ },
130
+ ]
131
+ ` ) ;
34
132
} ) ;
35
133
36
134
test ( 'does not trigger event when pressable is disabled' , async ( ) => {
You can’t perform that action at this time.
0 commit comments