I'm working on a React component library that was bootstrapped initially with TSDX (v0.14.1). After upgrading React from 17 to 18 and Storybook from 6.5.16 to 7.6.20, all my Jest tests stopped working and threw an error saying: TypeError: Jest: a transform must export a process function
My jest.config.js
looks like this:
/** @type {import('jest').Config} */
const config = {
setupFilesAfterEnv: ['jest-expect-message'],
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/__mocks__/fileMock.js',
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
},
};
module.exports = config;
I'm using:
React 18.x
Jest 27.3.1
TSDX 0.14.1
Storybook 7.6.20
I tried to add the dev dependency ts-jest, but it didn't resolve the issue.
Has anyone faced this issue? Is there a known compatibility issue with Jest 27 and React 18 in a TSDX setup?
Remove jest
from package.json
TSDX includes an internal Jest setup.
Add testEnvironment: 'jsdom'
to your jest.config.js
:
/** @type {import('jest').Config} */
const config = {
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['jest-expect-message'],
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/__mocks__/fileMock.js',
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
},
};
module.exports = config;