react-native-gesture-handler: TypeError: _RNGestureHandlerModule.default.flushOperations is not a function
Description
Issue with typing on the new version 2.4.0, the tests where we use Scrollable View (FlatList, ScrollView …) does not pass anymore
TypeError: _RNGestureHandlerModule.default.flushOperations is not a function
at Timeout._onTimeout (node_modules/react-native-gesture-handler/lib/commonjs/handlers/gestureHandlerCommon.ts:194:30)
Platforms
- iOS
- Android
- Web
Screenshots
Steps To Reproduce
-
update to new version 2.4.0 from version 2.3.1
-
write component that uses ScrollView for example
-
run test
-
test will fail with following error => ` TypeError: _RNGestureHandlerModule.default.flushOperations is not a function
at Timeout._onTimeout (node_modules/react-native-gesture-handler/lib/commonjs/handlers/gestureHandlerCommon.ts:194:30)`
Expected behavior
Actual behavior
Snack or minimal code example
`import { ReactElement } from ‘react’; import { View, useWindowDimensions, ActivityIndicator } from ‘react-native’; import { ScrollView } from ‘react-native-gesture-handler’; import RenderHTML from ‘react-native-render-html’; import { useNavigation, useRoute } from ‘@react-navigation/native’;
import { useTranslation } from ‘src/Shared/Config’; import { Color, routeNames, sharedStyles, tagsStyle } from ‘src/Shared/constants’; import { SettingsHeader } from ‘…/SubComponents’; import { styles } from ‘./PrivacyPolicyScreen.style’; import { SettingsScreenProps, SettingsTermsOfUseProps } from ‘src/Router/types.router’;
export const PrivacyPolicyScreen = (): ReactElement => { const { t } = useTranslation(); const { params: { uri }, } = useRoute<SettingsTermsOfUseProps[‘route’]>(); const { goBack, navigate } = useNavigation<SettingsScreenProps[‘navigation’]>(); const { width: screenWidth } = useWindowDimensions();
const onClose = () => { navigate(routeNames.App); };
return ( <View testID=“privacyPolicyScreenContainer” style={[sharedStyles.fullFlex, styles.container]}> <SettingsHeader title={t(‘settings_privacy_policy_item’)} onLeftPress={goBack} onRightPress={onClose} /> <ScrollView testID="privacyPolicyScreenContent" contentContainerStyle={styles.contentContainer} style={styles.content} > <RenderHTML source={{ uri }} contentWidth={screenWidth} tagsStyles={tagsStyle} remoteLoadingView={() => <ActivityIndicator size="large" color={Color.Blue} />} /> </ScrollView> </View> ); }; `
====== Jest Test ======
` it(‘click on terms of use to the correct page’, async () => { const { getByTestId } = render(<LegalNoticesScreen />);
const termOfUseEntry = getByTestId('testId-settings_page_item_terms_use');
expect(termOfUseEntry).toBeDefined();
await act(async () => {
fireEvent.press(termOfUseEntry);
});
await waitFor(() => expect(navContext.navigate).toHaveBeenCalledTimes(1));
expect(navContext.navigate).toHaveBeenNthCalledWith(1, routeNames.SettingsTermsOfUse, {
uri: 'https://partoo-mobile-app.s3.eu-west-1.amazonaws.com/terms-of-use/terms-of-use_fr.html',
});
});`
==== Error ==== TypeError: _RNGestureHandlerModule.default.flushOperations is not a function
at Timeout._onTimeout (node_modules/react-native-gesture-handler/lib/commonjs/handlers/gestureHandlerCommon.ts:194:30)
Package versions
- React: 17.0.2
- React Native: 0.67.4.
- React Native Gesture Handler: 2.4.0
- React Native Reanimated:2.7.0
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 22 (7 by maintainers)
Make sure you’ve setup Gesture Handler’s mocks correctly as described here, as it looks like mocks for GH module are missing.
I am not sure if its a similar issue but I am getting this error when running yarn test
in my package.json I have this
Also I have linked pods for IOS
@DominicGBauer Just released Gesture Handler 2.4.1 contains the fix for this issue.
@idrissakhi i had the same issue.
needed to apply similar changes to
node_modules/react-native-gesture-handler/lib/commonjs/mocks.js
error on node_modules/react-native-gesture-handler/src/mocks.ts not export method flushOperations
@idrissakhi the code under
lib/
is autogenerated, the 2.4.1 package includes changes in those files.We don’t import ScrollView from react-native-gesture-handler
Indeed, when adding a NOOP for flushOperations on mocks, all tests work again.
remove this line
import { ScrollView } from 'react-native-gesture-handler';
add this lineimport { ScrollView} from 'react-native';
run your test again, error only in test with imports from react-native-gesture-handler.