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

Add support for Jest 28+ #23

Merged
merged 2 commits into from
Jan 30, 2023
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-reanimated",
"version": "2.9.1-wp-2",
"version": "2.9.1-wp-3",
"description": "More powerful alternative to Animated library for React Native.",
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
Expand Down
Binary file removed react-native-reanimated-2.9.1-wp-2.tgz
Binary file not shown.
Binary file added react-native-reanimated-2.9.1-wp-3.tgz
Binary file not shown.
18 changes: 17 additions & 1 deletion src/reanimated2/jestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,23 @@ export const advanceAnimationByFrame = (count) => {
};

export const setUpTests = (userConfig = {}) => {
const expect = require('expect');
let expect = global.expect;
if (expect === undefined) {
const expectModule = require('expect');
expect = expectModule;
// Starting from Jest 28, "expect" package uses named exports instead of default export.
// So, requiring "expect" package doesn't give direct access to "expect" function anymore.
// It gives access to the module object instead.
// We use this info to detect if the project uses Jest 28 or higher.
if (typeof expect === 'object') {
const jestGlobals = require('@jest/globals');
expect = jestGlobals.expect;
}
if (expect === undefined || expect.extend === undefined) {
expect = expectModule.default;
}
}

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

Expand Down