File tree Expand file tree Collapse file tree
user-event/press/__tests__ Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -158,20 +158,14 @@ describe('fireEvent.press', () => {
158158 const onPressIn = jest . fn ( ) ;
159159 const onPressOut = jest . fn ( ) ;
160160 const onLongPress = jest . fn ( ) ;
161-
162- await render (
163- < View
164- testID = "subject"
165- // @ts -expect-error Intentionally passing test-only event props.
166- testOnly_onPress = { onPress }
167- // @ts -expect-error Intentionally passing test-only event props.
168- testOnly_onPressIn = { onPressIn }
169- // @ts -expect-error Intentionally passing test-only event props.
170- testOnly_onPressOut = { onPressOut }
171- // @ts -expect-error Intentionally passing test-only event props.
172- testOnly_onLongPress = { onLongPress }
173- /> ,
174- ) ;
161+ const testOnlyPressProps = {
162+ testOnly_onPress : onPress ,
163+ testOnly_onPressIn : onPressIn ,
164+ testOnly_onPressOut : onPressOut ,
165+ testOnly_onLongPress : onLongPress ,
166+ } ;
167+
168+ await render ( < View testID = "subject" { ...testOnlyPressProps } /> ) ;
175169
176170 const subject = screen . getByTestId ( 'subject' ) ;
177171
Original file line number Diff line number Diff line change @@ -77,20 +77,14 @@ describe('userEvent.longPress with fake timers', () => {
7777 test ( 'works with testOnly_onPress handlers' , async ( ) => {
7878 const { events, logEvent } = createEventLogger ( ) ;
7979 const user = userEvent . setup ( ) ;
80-
81- await render (
82- < View
83- testID = "subject"
84- // @ts -expect-error Intentionally passing test-only event props.
85- testOnly_onPress = { logEvent ( 'press' ) }
86- // @ts -expect-error Intentionally passing test-only event props.
87- testOnly_onPressIn = { logEvent ( 'pressIn' ) }
88- // @ts -expect-error Intentionally passing test-only event props.
89- testOnly_onPressOut = { logEvent ( 'pressOut' ) }
90- // @ts -expect-error Intentionally passing test-only event props.
91- testOnly_onLongPress = { logEvent ( 'longPress' ) }
92- /> ,
93- ) ;
80+ const testOnlyPressProps = {
81+ testOnly_onPress : logEvent ( 'press' ) ,
82+ testOnly_onPressIn : logEvent ( 'pressIn' ) ,
83+ testOnly_onPressOut : logEvent ( 'pressOut' ) ,
84+ testOnly_onLongPress : logEvent ( 'longPress' ) ,
85+ } ;
86+
87+ await render ( < View testID = "subject" { ...testOnlyPressProps } /> ) ;
9488
9589 await user . longPress ( screen . getByTestId ( 'subject' ) ) ;
9690 expect ( getEventsNames ( events ) ) . toEqual ( [ 'pressIn' , 'longPress' , 'pressOut' ] ) ;
Original file line number Diff line number Diff line change @@ -100,20 +100,14 @@ describe('userEvent.press with fake timers', () => {
100100 test ( 'works with testOnly_onPress handlers' , async ( ) => {
101101 const { events, logEvent } = createEventLogger ( ) ;
102102 const user = userEvent . setup ( ) ;
103+ const testOnlyPressProps = {
104+ testOnly_onPress : logEvent ( 'press' ) ,
105+ testOnly_onPressIn : logEvent ( 'pressIn' ) ,
106+ testOnly_onPressOut : logEvent ( 'pressOut' ) ,
107+ testOnly_onLongPress : logEvent ( 'longPress' ) ,
108+ } ;
103109
104- await render (
105- < View
106- testID = "subject"
107- // @ts -expect-error Intentionally passing test-only event props.
108- testOnly_onPress = { logEvent ( 'press' ) }
109- // @ts -expect-error Intentionally passing test-only event props.
110- testOnly_onPressIn = { logEvent ( 'pressIn' ) }
111- // @ts -expect-error Intentionally passing test-only event props.
112- testOnly_onPressOut = { logEvent ( 'pressOut' ) }
113- // @ts -expect-error Intentionally passing test-only event props.
114- testOnly_onLongPress = { logEvent ( 'longPress' ) }
115- /> ,
116- ) ;
110+ await render ( < View testID = "subject" { ...testOnlyPressProps } /> ) ;
117111
118112 await user . press ( screen . getByTestId ( 'subject' ) ) ;
119113 expect ( getEventsNames ( events ) ) . toEqual ( [ 'pressIn' , 'pressOut' , 'press' ] ) ;
You can’t perform that action at this time.
0 commit comments