Skip to content
Merged
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
20 changes: 14 additions & 6 deletions src/reanimated2/jestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,21 @@ export const advanceAnimationByFrame = (count) => {
};

export const setUpTests = (userConfig = {}) => {
let expect;
try {
expect = require('expect');
} catch (_) {
// for Jest in version 28+
const { expect: expectModule } = require('@jest/globals');
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');
Expand Down