Skip to content

Commit

Permalink
Support for Jest 28 (software-mansion#3347)
Browse files Browse the repository at this point in the history
## Description

Add support for Jest 28 with backward compatibility.

Based on: software-mansion#3217
  • Loading branch information
piaskowyk authored and fluiddot committed Jun 5, 2023
1 parent 2b5a762 commit f51b4f7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
8 changes: 7 additions & 1 deletion docs/docs/guide/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ To be sure, check if your `jest.config.js` file contains:
```js
...
preset: 'react-native',
setupFiles: ['./jest-setup.js'],
setupFilesAfterEnv: ['./jest-setup.js'],
...
```

:::caution

If you use Jest in a version **older than 28**, you should set `setupFiles` property instead of `setupFilesAfterEnv`

:::

If you have custom babel configuration for testing, make sure that Reanimated's babel plugin is enabled for that environment.

## API
Expand Down
8 changes: 7 additions & 1 deletion docs/versioned_docs/version-2.2.x/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ To be sure, check if your `jest.config.js` file contains:
```js
...
preset: 'react-native',
setupFiles: ['./jest-setup.js'],
setupFilesAfterEnv: ['./jest-setup.js'],
...
```

:::caution

If you use Jest in a version **older than 28**, you should set `setupFiles` property instead of `setupFilesAfterEnv`

:::

If you have custom babel configuration for testing, make sure that Reanimated's babel plugin is enabled for that environment.

## API
Expand Down
8 changes: 7 additions & 1 deletion docs/versioned_docs/version-2.3.x/guide/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ To be sure, check if your `jest.config.js` file contains:
```js
...
preset: 'react-native',
setupFiles: ['./jest-setup.js'],
setupFilesAfterEnv: ['./jest-setup.js'],
...
```

:::caution

If you use Jest in a version **older than 28**, you should set `setupFiles` property instead of `setupFilesAfterEnv`

:::

If you have custom babel configuration for testing, make sure that Reanimated's babel plugin is enabled for that environment.

## API
Expand Down
8 changes: 7 additions & 1 deletion docs/versioned_docs/version-2.5.x/guide/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ To be sure, check if your `jest.config.js` file contains:
```js
...
preset: 'react-native',
setupFiles: ['./jest-setup.js'],
setupFilesAfterEnv: ['./jest-setup.js'],
...
```

:::caution

If you use Jest in a version **older than 28**, you should set `setupFiles` property instead of `setupFilesAfterEnv`

:::

If you have custom babel configuration for testing, make sure that Reanimated's babel plugin is enabled for that environment.

## API
Expand Down
10 changes: 9 additions & 1 deletion src/reanimated2/jestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,15 @@ export const advanceAnimationByFrame = (count) => {
};

export const setUpTests = (userConfig = {}) => {
const expect = require('expect');
let expect;
try {
expect = require('expect');
} catch (_) {
// for Jest in version 28+
const { expect: expectModule } = require('@jest/globals');
expect = expectModule;
}

require('setimmediate');
frameTime = Math.round(1000 / config.fps);

Expand Down

0 comments on commit f51b4f7

Please sign in to comment.