Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Jest 28 #3347

Merged
merged 5 commits into from
Jul 1, 2022
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
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');
Copy link

@parasharrajat parasharrajat Aug 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will not throw on jest v28. As per the upgrade guide https://jestjs.io/docs/28.x/upgrading-to-jest28#expect, expect here will be set to undefined and no error. i.e. Catch will never fire.

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

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

Expand Down