@@ -29,38 +29,12 @@ const WithoutEventComponent = (_props: WithoutEventComponentProps) => (
29
29
</ View >
30
30
) ;
31
31
32
- type CustomEventComponentProps = {
33
- onCustomEvent : ( ) => void ;
34
- } ;
35
- const CustomEventComponent = ( { onCustomEvent } : CustomEventComponentProps ) => (
36
- < TouchableOpacity onPress = { onCustomEvent } >
37
- < Text > Custom event component</ Text >
38
- </ TouchableOpacity >
39
- ) ;
40
-
41
- type MyCustomButtonProps = {
42
- handlePress : ( ) => void ;
43
- text : string ;
44
- } ;
45
- const MyCustomButton = ( { handlePress, text } : MyCustomButtonProps ) => (
46
- < OnPressComponent onPress = { handlePress } text = { text } />
47
- ) ;
48
-
49
- type CustomEventComponentWithCustomNameProps = {
50
- handlePress : ( ) => void ;
51
- } ;
52
- const CustomEventComponentWithCustomName = ( {
53
- handlePress,
54
- } : CustomEventComponentWithCustomNameProps ) => (
55
- < MyCustomButton handlePress = { handlePress } text = "Custom component" />
56
- ) ;
57
-
58
32
describe ( 'fireEvent' , ( ) => {
59
33
test ( 'should invoke specified event' , ( ) => {
60
34
const onPressMock = jest . fn ( ) ;
61
35
render ( < OnPressComponent onPress = { onPressMock } text = "Press me" /> ) ;
62
36
63
- fireEvent ( screen . getByText ( 'Press me' ) , 'press' ) ;
37
+ fireEvent . press ( screen . getByText ( 'Press me' ) ) ;
64
38
65
39
expect ( onPressMock ) . toHaveBeenCalled ( ) ;
66
40
} ) ;
@@ -70,7 +44,7 @@ describe('fireEvent', () => {
70
44
const text = 'New press text' ;
71
45
render ( < OnPressComponent onPress = { onPressMock } text = { text } /> ) ;
72
46
73
- fireEvent ( screen . getByText ( text ) , 'press' ) ;
47
+ fireEvent . press ( screen . getByText ( text ) ) ;
74
48
expect ( onPressMock ) . toHaveBeenCalled ( ) ;
75
49
} ) ;
76
50
@@ -83,26 +57,11 @@ describe('fireEvent', () => {
83
57
fireEvent ( screen . getByText ( 'Without event' ) , 'press' ) ;
84
58
expect ( onPressMock ) . not . toHaveBeenCalled ( ) ;
85
59
} ) ;
86
-
87
- test ( 'should invoke event with custom name' , ( ) => {
88
- const handlerMock = jest . fn ( ) ;
89
- const EVENT_DATA = 'event data' ;
90
-
91
- render (
92
- < View >
93
- < CustomEventComponent onCustomEvent = { handlerMock } />
94
- </ View > ,
95
- ) ;
96
-
97
- fireEvent ( screen . getByText ( 'Custom event component' ) , 'customEvent' , EVENT_DATA ) ;
98
-
99
- expect ( handlerMock ) . toHaveBeenCalledWith ( EVENT_DATA ) ;
100
- } ) ;
101
60
} ) ;
102
61
103
62
test ( 'fireEvent.press' , ( ) => {
104
63
const onPressMock = jest . fn ( ) ;
105
- const text = 'Fireevent press' ;
64
+ const text = 'FireEvent press' ;
106
65
const eventData = {
107
66
nativeEvent : {
108
67
pageX : 20 ,
@@ -113,7 +72,8 @@ test('fireEvent.press', () => {
113
72
114
73
fireEvent . press ( screen . getByText ( text ) , eventData ) ;
115
74
116
- expect ( onPressMock ) . toHaveBeenCalledWith ( eventData ) ;
75
+ expect ( onPressMock ) . toHaveBeenCalledTimes ( 1 ) ;
76
+ expect ( onPressMock . mock . calls [ 0 ] [ 0 ] . nativeEvent ) . toMatchObject ( eventData . nativeEvent ) ;
117
77
} ) ;
118
78
119
79
test ( 'fireEvent.scroll' , ( ) => {
@@ -161,26 +121,6 @@ it('sets native state value for unmanaged text inputs', () => {
161
121
expect ( input ) . toHaveDisplayValue ( 'abc' ) ;
162
122
} ) ;
163
123
164
- test ( 'custom component with custom event name' , ( ) => {
165
- const handlePress = jest . fn ( ) ;
166
-
167
- render ( < CustomEventComponentWithCustomName handlePress = { handlePress } /> ) ;
168
-
169
- fireEvent ( screen . getByText ( 'Custom component' ) , 'handlePress' ) ;
170
-
171
- expect ( handlePress ) . toHaveBeenCalled ( ) ;
172
- } ) ;
173
-
174
- test ( 'event with multiple handler parameters' , ( ) => {
175
- const handlePress = jest . fn ( ) ;
176
-
177
- render ( < CustomEventComponentWithCustomName handlePress = { handlePress } /> ) ;
178
-
179
- fireEvent ( screen . getByText ( 'Custom component' ) , 'handlePress' , 'param1' , 'param2' ) ;
180
-
181
- expect ( handlePress ) . toHaveBeenCalledWith ( 'param1' , 'param2' ) ;
182
- } ) ;
183
-
184
124
test ( 'should not fire on disabled TouchableOpacity' , ( ) => {
185
125
const handlePress = jest . fn ( ) ;
186
126
render (
@@ -250,8 +190,7 @@ test('should fire inside View with pointerEvents="box-none"', () => {
250
190
) ;
251
191
252
192
fireEvent . press ( screen . getByText ( 'Trigger' ) ) ;
253
- fireEvent ( screen . getByText ( 'Trigger' ) , 'onPress' ) ;
254
- expect ( onPress ) . toHaveBeenCalledTimes ( 2 ) ;
193
+ expect ( onPress ) . toHaveBeenCalledTimes ( 1 ) ;
255
194
} ) ;
256
195
257
196
test ( 'should fire inside View with pointerEvents="auto"' , ( ) => {
@@ -265,8 +204,7 @@ test('should fire inside View with pointerEvents="auto"', () => {
265
204
) ;
266
205
267
206
fireEvent . press ( screen . getByText ( 'Trigger' ) ) ;
268
- fireEvent ( screen . getByText ( 'Trigger' ) , 'onPress' ) ;
269
- expect ( onPress ) . toHaveBeenCalledTimes ( 2 ) ;
207
+ expect ( onPress ) . toHaveBeenCalledTimes ( 1 ) ;
270
208
} ) ;
271
209
272
210
test ( 'should not fire deeply inside View with pointerEvents="box-only"' , ( ) => {
0 commit comments