diff --git a/packages/docs-gesture-handler/docs/guides/testing.md b/packages/docs-gesture-handler/docs/guides/testing.mdx similarity index 70% rename from packages/docs-gesture-handler/docs/guides/testing.md rename to packages/docs-gesture-handler/docs/guides/testing.mdx index 788a523347..ecefa47ae5 100644 --- a/packages/docs-gesture-handler/docs/guides/testing.md +++ b/packages/docs-gesture-handler/docs/guides/testing.mdx @@ -4,23 +4,62 @@ title: Testing with Jest sidebar_position: 4 --- -## Mocking native modules +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; -In order to load mocks provided by RNGH, add the following to your jest config in `package.json`: +## Setup -```json -"setupFiles": ["./node_modules/react-native-gesture-handler/jestSetup.js"] +### Jest configuration + +In order to use functions provided by Gesture Handler, add `react-native-gesture-handler` to `transformIgnorePatterns` in jest config. + +```js +transformIgnorePatterns: [ + 'node_modules/(?!((jest-)?react-native|react-native-gesture-handler)/)', +], ``` -Example: +:::note +Be careful when adding multiple entries to `transformIgnorePatterns`. Since `Jest` ignores a file if it matches any pattern in the list, splitting negative lookaheads into separate strings often causes them to override each other. It is safer to combine your exceptions into a single regex using the `|` operator. See the [Jest documentation](https://jestjs.io/docs/tutorial-react-native#transformignorepatterns-customization) for an example. +::: + +### Mocking native modules + +In order to load mocks provided by RNGH, add the following to your jest config: ```json -"jest": { - "preset": "react-native", - "setupFiles": ["./node_modules/react-native-gesture-handler/jestSetup.js"] -} +"setupFiles": ["./node_modules/react-native-gesture-handler/jestSetup.js"] ``` +### Example jest config + + + + ```js + module.exports = { + preset: '@react-native/jest-preset', + transformIgnorePatterns: [ + 'node_modules/(?!((jest-)?react-native|react-native-gesture-handler)/)', + ], + setupFiles: ['react-native-gesture-handler/jestSetup.js'], + }; + ``` + + + ```json + "jest": { + "preset": "@react-native/jest-preset", + "transformIgnorePatterns": [ + "node_modules/(?!((jest-)?react-native|react-native-gesture-handler)/)" + ], + "setupFiles": [ + "react-native-gesture-handler/jestSetup.js" + ] + } + ``` + + + ## Testing Gestures' and Gesture handlers' callbacks RNGH provides APIs, specifically [`fireGestureHandler`](#firegesturehandler) and [`getByGestureTestId`](#getbygesturetestid), to trigger selected handlers. diff --git a/packages/react-native-gesture-handler/ReanimatedDrawerLayout/package.json b/packages/react-native-gesture-handler/ReanimatedDrawerLayout/package.json index 2ce199ec5a..9e84eea779 100644 --- a/packages/react-native-gesture-handler/ReanimatedDrawerLayout/package.json +++ b/packages/react-native-gesture-handler/ReanimatedDrawerLayout/package.json @@ -1,5 +1,5 @@ { - "main": "../lib/commonjs/components/ReanimatedDrawerLayout", + "main": "../lib/module/components/ReanimatedDrawerLayout", "module": "../lib/module/components/ReanimatedDrawerLayout", "react-native": "../src/components/ReanimatedDrawerLayout", "types": "../lib/typescript/components/ReanimatedDrawerLayout.d.ts" diff --git a/packages/react-native-gesture-handler/ReanimatedSwipeable/package.json b/packages/react-native-gesture-handler/ReanimatedSwipeable/package.json index 5569615eb2..4e20e4a090 100644 --- a/packages/react-native-gesture-handler/ReanimatedSwipeable/package.json +++ b/packages/react-native-gesture-handler/ReanimatedSwipeable/package.json @@ -1,5 +1,5 @@ { - "main": "../lib/commonjs/components/ReanimatedSwipeable/", + "main": "../lib/module/components/ReanimatedSwipeable/", "module": "../lib/module/components/ReanimatedSwipeable/", "react-native": "../src/components/ReanimatedSwipeable/", "types": "../lib/typescript/components/ReanimatedSwipeable/" diff --git a/packages/react-native-gesture-handler/jest-utils/package.json b/packages/react-native-gesture-handler/jest-utils/package.json index 5e0f521722..f6fb277781 100644 --- a/packages/react-native-gesture-handler/jest-utils/package.json +++ b/packages/react-native-gesture-handler/jest-utils/package.json @@ -1,5 +1,5 @@ { - "main": "../lib/commonjs/jestUtils/index", + "main": "../lib/module/jestUtils/index", "module": "../lib/module/jestUtils/index", "react-native": "../src/jestUtils/index", "types": "../lib/typescript/jestUtils/index.d.ts"