@@ -11,9 +11,22 @@ import {
11
11
} from 'react-native' ;
12
12
import { render , fireEvent } from '..' ;
13
13
14
- const OnPressComponent = ( { onPress, text } ) => (
14
+ const OnPressComponent = ( {
15
+ onPress,
16
+ onLongPress,
17
+ onPressIn,
18
+ onPressOut,
19
+ onFocus,
20
+ text,
21
+ } ) => (
15
22
< View >
16
- < TouchableOpacity onPress = { onPress } >
23
+ < TouchableOpacity
24
+ onPress = { onPress }
25
+ onLongPress = { onLongPress }
26
+ onPressIn = { onPressIn }
27
+ onPressOut = { onPressOut }
28
+ onFocus = { onFocus }
29
+ >
17
30
< Text > { text } </ Text >
18
31
</ TouchableOpacity >
19
32
</ View >
@@ -100,6 +113,86 @@ test('fireEvent.press', () => {
100
113
expect ( onPressMock ) . toHaveBeenCalled ( ) ;
101
114
} ) ;
102
115
116
+ test ( 'fireEvent.press all events' , ( ) => {
117
+ const callOrder = [ ] ;
118
+ const onPressInMock = jest . fn ( ( ) => callOrder . push ( 'onPressIn' ) ) ;
119
+ const onPressOutMock = jest . fn ( ( ) => callOrder . push ( 'onPressOut' ) ) ;
120
+ const onPressMock = jest . fn ( ( ) => callOrder . push ( 'onPress' ) ) ;
121
+ const onFocusMock = jest . fn ( ( ) => callOrder . push ( 'onFocus' ) ) ;
122
+ const onLongPressMock = jest . fn ( ) ;
123
+ const text = 'Fireevent press' ;
124
+ const { getByText } = render (
125
+ < OnPressComponent
126
+ onPress = { onPressMock }
127
+ onLongPress = { onLongPressMock }
128
+ onPressIn = { onPressInMock }
129
+ onPressOut = { onPressOutMock }
130
+ onFocus = { onFocusMock }
131
+ text = { text }
132
+ />
133
+ ) ;
134
+
135
+ fireEvent . press ( getByText ( text ) ) ;
136
+
137
+ expect ( onLongPressMock ) . not . toHaveBeenCalled ( ) ;
138
+ expect ( onPressInMock ) . toHaveBeenCalled ( ) ;
139
+ expect ( onPressOutMock ) . toHaveBeenCalled ( ) ;
140
+ expect ( onPressMock ) . toHaveBeenCalled ( ) ;
141
+ expect ( onFocusMock ) . toHaveBeenCalled ( ) ;
142
+ expect ( callOrder ) . toStrictEqual ( [
143
+ 'onPressIn' ,
144
+ 'onPressOut' ,
145
+ 'onPress' ,
146
+ 'onFocus' ,
147
+ ] ) ;
148
+ } ) ;
149
+
150
+ test ( 'fireEvent.longPress' , ( ) => {
151
+ const onLongPressMock = jest . fn ( ) ;
152
+ const text = 'Fireevent longpress' ;
153
+ const { getByText } = render (
154
+ < OnPressComponent onLongPress = { onLongPressMock } text = { text } />
155
+ ) ;
156
+
157
+ fireEvent . longPress ( getByText ( text ) ) ;
158
+
159
+ expect ( onLongPressMock ) . toHaveBeenCalled ( ) ;
160
+ } ) ;
161
+
162
+ test ( 'fireEvent.longPress all events' , ( ) => {
163
+ const callOrder = [ ] ;
164
+ const onPressInMock = jest . fn ( ( ) => callOrder . push ( 'onPressIn' ) ) ;
165
+ const onLongPressMock = jest . fn ( ( ) => callOrder . push ( 'onLongPress' ) ) ;
166
+ const onPressOutMock = jest . fn ( ( ) => callOrder . push ( 'onPressOut' ) ) ;
167
+ const onPressMock = jest . fn ( ) ;
168
+ const onFocusMock = jest . fn ( ( ) => callOrder . push ( 'onFocus' ) ) ;
169
+ const text = 'Fireevent longpress' ;
170
+ const { getByText } = render (
171
+ < OnPressComponent
172
+ onPress = { onPressMock }
173
+ onLongPress = { onLongPressMock }
174
+ onPressIn = { onPressInMock }
175
+ onPressOut = { onPressOutMock }
176
+ onFocus = { onFocusMock }
177
+ text = { text }
178
+ />
179
+ ) ;
180
+
181
+ fireEvent . longPress ( getByText ( text ) ) ;
182
+
183
+ expect ( onPressInMock ) . toHaveBeenCalled ( ) ;
184
+ expect ( onLongPressMock ) . toHaveBeenCalled ( ) ;
185
+ expect ( onPressOutMock ) . toHaveBeenCalled ( ) ;
186
+ expect ( onPressMock ) . not . toHaveBeenCalled ( ) ;
187
+ expect ( onFocusMock ) . toHaveBeenCalled ( ) ;
188
+ expect ( callOrder ) . toStrictEqual ( [
189
+ 'onPressIn' ,
190
+ 'onLongPress' ,
191
+ 'onPressOut' ,
192
+ 'onFocus' ,
193
+ ] ) ;
194
+ } ) ;
195
+
103
196
test ( 'fireEvent.scroll' , ( ) => {
104
197
const onScrollMock = jest . fn ( ) ;
105
198
const eventData = {
0 commit comments