@@ -29,38 +29,12 @@ const WithoutEventComponent = (_props: WithoutEventComponentProps) => (
2929 </ View >
3030) ;
3131
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-
5832describe ( 'fireEvent' , ( ) => {
5933 test ( 'should invoke specified event' , ( ) => {
6034 const onPressMock = jest . fn ( ) ;
6135 render ( < OnPressComponent onPress = { onPressMock } text = "Press me" /> ) ;
6236
63- fireEvent ( screen . getByText ( 'Press me' ) , 'press' ) ;
37+ fireEvent . press ( screen . getByText ( 'Press me' ) ) ;
6438
6539 expect ( onPressMock ) . toHaveBeenCalled ( ) ;
6640 } ) ;
@@ -70,7 +44,7 @@ describe('fireEvent', () => {
7044 const text = 'New press text' ;
7145 render ( < OnPressComponent onPress = { onPressMock } text = { text } /> ) ;
7246
73- fireEvent ( screen . getByText ( text ) , 'press' ) ;
47+ fireEvent . press ( screen . getByText ( text ) ) ;
7448 expect ( onPressMock ) . toHaveBeenCalled ( ) ;
7549 } ) ;
7650
@@ -83,26 +57,11 @@ describe('fireEvent', () => {
8357 fireEvent ( screen . getByText ( 'Without event' ) , 'press' ) ;
8458 expect ( onPressMock ) . not . toHaveBeenCalled ( ) ;
8559 } ) ;
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- } ) ;
10160} ) ;
10261
10362test ( 'fireEvent.press' , ( ) => {
10463 const onPressMock = jest . fn ( ) ;
105- const text = 'Fireevent press' ;
64+ const text = 'FireEvent press' ;
10665 const eventData = {
10766 nativeEvent : {
10867 pageX : 20 ,
@@ -113,7 +72,8 @@ test('fireEvent.press', () => {
11372
11473 fireEvent . press ( screen . getByText ( text ) , eventData ) ;
11574
116- expect ( onPressMock ) . toHaveBeenCalledWith ( eventData ) ;
75+ expect ( onPressMock ) . toHaveBeenCalledTimes ( 1 ) ;
76+ expect ( onPressMock . mock . calls [ 0 ] [ 0 ] . nativeEvent ) . toMatchObject ( eventData . nativeEvent ) ;
11777} ) ;
11878
11979test ( 'fireEvent.scroll' , ( ) => {
@@ -161,26 +121,6 @@ it('sets native state value for unmanaged text inputs', () => {
161121 expect ( input ) . toHaveDisplayValue ( 'abc' ) ;
162122} ) ;
163123
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-
184124test ( 'should not fire on disabled TouchableOpacity' , ( ) => {
185125 const handlePress = jest . fn ( ) ;
186126 render (
@@ -250,8 +190,7 @@ test('should fire inside View with pointerEvents="box-none"', () => {
250190 ) ;
251191
252192 fireEvent . press ( screen . getByText ( 'Trigger' ) ) ;
253- fireEvent ( screen . getByText ( 'Trigger' ) , 'onPress' ) ;
254- expect ( onPress ) . toHaveBeenCalledTimes ( 2 ) ;
193+ expect ( onPress ) . toHaveBeenCalledTimes ( 1 ) ;
255194} ) ;
256195
257196test ( 'should fire inside View with pointerEvents="auto"' , ( ) => {
@@ -265,8 +204,7 @@ test('should fire inside View with pointerEvents="auto"', () => {
265204 ) ;
266205
267206 fireEvent . press ( screen . getByText ( 'Trigger' ) ) ;
268- fireEvent ( screen . getByText ( 'Trigger' ) , 'onPress' ) ;
269- expect ( onPress ) . toHaveBeenCalledTimes ( 2 ) ;
207+ expect ( onPress ) . toHaveBeenCalledTimes ( 1 ) ;
270208} ) ;
271209
272210test ( 'should not fire deeply inside View with pointerEvents="box-only"' , ( ) => {
0 commit comments