@@ -58,8 +58,12 @@ function assertGestureControllerTypes(pan: PanGesture, tap: TapGesture) {
5858
5959void assertGestureControllerTypes ;
6060
61+ function getControllerState ( gesture : object ) : State {
62+ return ( gesture as { state : State } ) . state ;
63+ }
64+
6165describe ( 'createGestureController' , ( ) => {
62- test ( 'allows assertions after each gesture lifecycle step' , ( ) => {
66+ test ( 'transitions to the expected state after each gesture lifecycle step' , ( ) => {
6367 const { order, callbacks } = mockedContinuousCallbacks ( ) ;
6468 const pan = renderHook ( ( ) =>
6569 usePanGesture ( { disableReanimated : true , ...callbacks } )
@@ -68,38 +72,38 @@ describe('createGestureController', () => {
6872
6973 gesture . begin ( { translationX : 0 } ) ;
7074
71- expect ( gesture . getState ( ) ) . toBe ( State . BEGAN ) ;
7275 expect ( order ) . toEqual ( [ 'onBegin' ] ) ;
76+ expect ( getControllerState ( gesture ) ) . toBe ( State . BEGAN ) ;
7377 expect ( callbacks . onBegin ) . toHaveBeenCalledWith (
7478 expect . objectContaining ( { translationX : 0 } )
7579 ) ;
7680
7781 gesture . activate ( { translationX : 10 } ) ;
7882
79- expect ( gesture . getState ( ) ) . toBe ( State . ACTIVE ) ;
8083 expect ( order ) . toEqual ( [ 'onBegin' , 'onActivate' ] ) ;
84+ expect ( getControllerState ( gesture ) ) . toBe ( State . ACTIVE ) ;
8185 expect ( callbacks . onActivate ) . toHaveBeenCalledWith (
8286 expect . objectContaining ( { translationX : 10 } )
8387 ) ;
8488
8589 gesture . update ( { translationX : 50 } ) ;
8690
87- expect ( gesture . getState ( ) ) . toBe ( State . ACTIVE ) ;
8891 expect ( order ) . toEqual ( [ 'onBegin' , 'onActivate' , 'onUpdate' ] ) ;
92+ expect ( getControllerState ( gesture ) ) . toBe ( State . ACTIVE ) ;
8993 expect ( callbacks . onUpdate ) . toHaveBeenCalledWith (
9094 expect . objectContaining ( { translationX : 50 } )
9195 ) ;
9296
9397 gesture . end ( { translationX : 50 } ) ;
9498
95- expect ( gesture . getState ( ) ) . toBe ( State . END ) ;
9699 expect ( order ) . toEqual ( [
97100 'onBegin' ,
98101 'onActivate' ,
99102 'onUpdate' ,
100103 'onDeactivate' ,
101104 'onFinalize' ,
102105 ] ) ;
106+ expect ( getControllerState ( gesture ) ) . toBe ( State . END ) ;
103107 expect ( callbacks . onFinalize ) . toHaveBeenCalledWith (
104108 expect . objectContaining ( { canceled : false , translationX : 50 } )
105109 ) ;
@@ -115,8 +119,8 @@ describe('createGestureController', () => {
115119 gesture . begin ( { x : 10 } ) ;
116120 gesture . fail ( { x : 10 } ) ;
117121
118- expect ( gesture . getState ( ) ) . toBe ( State . FAILED ) ;
119122 expect ( order ) . toEqual ( [ 'onBegin' , 'onFinalize' ] ) ;
123+ expect ( getControllerState ( gesture ) ) . toBe ( State . FAILED ) ;
120124 expect ( callbacks . onActivate ) . not . toHaveBeenCalled ( ) ;
121125 expect ( callbacks . onDeactivate ) . not . toHaveBeenCalled ( ) ;
122126 expect ( callbacks . onFinalize ) . toHaveBeenCalledWith (
@@ -180,33 +184,36 @@ describe('createGestureController', () => {
180184 gesture . begin ( ) ;
181185 gesture [ terminalAction ] ( ) ;
182186
183- expect ( gesture . getState ( ) ) . toBe ( terminalState ) ;
187+ expect ( getControllerState ( gesture ) ) . toBe ( terminalState ) ;
184188
185189 gesture . begin ( ) ;
186190
187- expect ( gesture . getState ( ) ) . toBe ( State . BEGAN ) ;
191+ expect ( getControllerState ( gesture ) ) . toBe ( State . BEGAN ) ;
188192
189193 gesture [ terminalAction ] ( ) ;
190194
191- expect ( gesture . getState ( ) ) . toBe ( terminalState ) ;
195+ expect ( getControllerState ( gesture ) ) . toBe ( terminalState ) ;
192196 expect ( onBegin ) . toHaveBeenCalledTimes ( 2 ) ;
193197 expect ( onFinalize ) . toHaveBeenCalledTimes ( 2 ) ;
194198 }
195199 ) ;
196200
197201 test ( 'rejects raw state-machine fields in event payloads' , ( ) => {
198- const tap = renderHook ( ( ) => useTapGesture ( { disableReanimated : true } ) )
199- . result . current ;
202+ const onBegin = jest . fn ( ) ;
203+ const tap = renderHook ( ( ) =>
204+ useTapGesture ( { disableReanimated : true , onBegin } )
205+ ) . result . current ;
200206 const gesture = createGestureController ( tap ) ;
201207
202208 expect ( ( ) => gesture . begin ( { state : State . BEGAN } as never ) ) . toThrow (
203209 "createGestureController manages 'state' internally."
204210 ) ;
205- expect ( gesture . getState ( ) ) . toBe ( State . UNDETERMINED ) ;
211+ expect ( getControllerState ( gesture ) ) . toBe ( State . UNDETERMINED ) ;
212+ expect ( onBegin ) . not . toHaveBeenCalled ( ) ;
206213
207214 gesture . begin ( ) ;
208215
209- expect ( gesture . getState ( ) ) . toBe ( State . BEGAN ) ;
216+ expect ( getControllerState ( gesture ) ) . toBe ( State . BEGAN ) ;
210217 } ) ;
211218
212219 test ( 'uses the latest callbacks after rerender' , ( ) => {
@@ -241,13 +248,13 @@ describe('createGestureController', () => {
241248 hook . rerender ( { enabled : false } ) ;
242249 gesture . begin ( ) ;
243250
244- expect ( gesture . getState ( ) ) . toBe ( State . UNDETERMINED ) ;
251+ expect ( getControllerState ( gesture ) ) . toBe ( State . UNDETERMINED ) ;
245252 expect ( onBegin ) . not . toHaveBeenCalled ( ) ;
246253
247254 hook . rerender ( { enabled : true } ) ;
248255 gesture . begin ( ) ;
249256
250- expect ( gesture . getState ( ) ) . toBe ( State . BEGAN ) ;
257+ expect ( getControllerState ( gesture ) ) . toBe ( State . BEGAN ) ;
251258 expect ( onBegin ) . toHaveBeenCalledTimes ( 1 ) ;
252259 } ) ;
253260
@@ -267,7 +274,7 @@ describe('createGestureController', () => {
267274 gesture . update ( { translationX : 50 } ) ;
268275 gesture . end ( ) ;
269276
270- expect ( gesture . getState ( ) ) . toBe ( State . UNDETERMINED ) ;
277+ expect ( getControllerState ( gesture ) ) . toBe ( State . UNDETERMINED ) ;
271278 expect ( order ) . toEqual ( [ ] ) ;
272279 } ) ;
273280} ) ;
0 commit comments