File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -181,6 +181,29 @@ describe("useSwipeable", () => {
181181 ) ;
182182 } ) ;
183183
184+ it ( "correctly tracks the first event" , ( ) => {
185+ const onSwiping = jest . fn ( ) ;
186+ const { getByText } = render ( < SwipeableUsingHook onSwiping = { onSwiping } /> ) ;
187+
188+ const touchArea = getByText ( TESTING_TEXT ) ;
189+
190+ fireEvent [ TS ] ( touchArea , cte ( { x : 100 , y : 100 } ) ) ;
191+ fireEvent [ TM ] ( touchArea , cte ( { x : 100 , y : 125 } ) ) ;
192+ fireEvent [ TM ] ( touchArea , cte ( { x : 100 , y : 150 } ) ) ;
193+ fireEvent [ TM ] ( touchArea , cte ( { x : 100 , y : 175 } ) ) ;
194+ fireEvent [ TE ] ( touchArea , cte ( { } ) ) ;
195+
196+ expect ( onSwiping . mock . calls [ 0 ] [ 0 ] ) . toEqual (
197+ expect . objectContaining ( { first : true } )
198+ ) ;
199+ expect ( onSwiping . mock . calls [ 1 ] [ 0 ] ) . toEqual (
200+ expect . objectContaining ( { first : false } )
201+ ) ;
202+ expect ( onSwiping . mock . calls [ 2 ] [ 0 ] ) . toEqual (
203+ expect . objectContaining ( { first : false } )
204+ ) ;
205+ } ) ;
206+
184207 it ( "calls preventDefault when swiping in direction that has a callback" , ( ) => {
185208 const onSwipedDown = jest . fn ( ) ;
186209
Original file line number Diff line number Diff line change @@ -166,10 +166,11 @@ function getHandlers(
166166 )
167167 event . preventDefault ( ) ;
168168
169- // first is now always false
170169 return {
171170 ...state ,
172- eventData : { ...eventData , first : false } ,
171+ // first is now always false
172+ first : false ,
173+ eventData,
173174 swiping : true ,
174175 } ;
175176 } ) ;
You can’t perform that action at this time.
0 commit comments