Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Jest] Don't fire callbacks on disabled gestures (#3119)
## Description As pointed in #3117, `fireGestureHandler` runs callback function even if gesture has been marked as disabled with `enable(false)`. This PR removes this behavior. Closes #3117 ## Test plan <details> <summary>Run the following test:</summary> ```tsx import React from 'react'; import { View } from 'react-native'; import Animated from 'react-native-reanimated'; import { Gesture, GestureDetector, GestureHandlerRootView, TapGestureHandler, type TapGesture, } from '../'; import { fireGestureHandler, getByGestureTestId } from '../jestUtils'; import { render } from '@testing-library/react-native'; import Mocks from '../mocks'; type ComponentProps = { enabled: boolean; callback: () => void; }; const Component = ({ enabled, callback }: ComponentProps) => { const tap = Gesture.Tap() .withTestId('tap') .enabled(enabled) .runOnJS(true) .onEnd(callback); return ( <GestureDetector gesture={tap}> <Animated.View style={{ width: 200, height: 200, backgroundColor: 'orange' }} /> </GestureDetector> ); }; describe('Some Random Tests', () => { type TestData = { title: string; enabled: boolean; timesCalled: number; }; it.each<TestData>([ { title: 'should trigger callback once', enabled: true, timesCalled: 1 }, { title: 'should not trigger callback', enabled: false, timesCalled: 0 }, ])('$title', ({ enabled, timesCalled }) => { const callback = jest.fn(); render(<Component enabled={enabled} callback={callback} />); fireGestureHandler<TapGesture>(getByGestureTestId('tap')); expect(callback).toHaveBeenCalledTimes(timesCalled); }); }); describe('Button test', () => { const callback = jest.fn(); const { getByTestId } = render( <Mocks.RectButton enabled={false} onPress={callback} testID="btn" /> ); fireGestureHandler(getByTestId('btn')); expect(callback).toHaveBeenCalledTimes(0); }); describe('Old API test', () => { const callback = jest.fn(); const { getByTestId } = render( <GestureHandlerRootView> <TapGestureHandler testID="tap" onActivated={callback} enabled={false}> <View /> </TapGestureHandler> </GestureHandlerRootView> ); fireGestureHandler(getByTestId('tap')); expect(callback).toHaveBeenCalledTimes(0); }); ``` </details>
- Loading branch information