Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

<Tabs groupId="package-managers">
<TabItem value="js" label="jest.config.js" default>
```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'],
};
```
</TabItem>
<TabItem value="json" label="package.json">
```json
"jest": {
"preset": "@react-native/jest-preset",
"transformIgnorePatterns": [
"node_modules/(?!((jest-)?react-native|react-native-gesture-handler)/)"
],
"setupFiles": [
"react-native-gesture-handler/jestSetup.js"
]
}
```
</TabItem>
</Tabs>

## Testing Gestures' and Gesture handlers' callbacks

RNGH provides APIs, specifically [`fireGestureHandler`](#firegesturehandler) and [`getByGestureTestId`](#getbygesturetestid), to trigger selected handlers.
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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/"
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Loading