Evaluate can't run in jest with react-native #2448
-
It works in react native's app, but dosen't work in jest. There are key files: // case.test.tsx
import { evaluateSync } from '@mdx-js/mdx'
import * as runtime from 'react/jsx-runtime'
it('renders with crashing', () => {
evaluateSync('1', runtime as any) // => TypeError: Cannot redefine property: arguments at Function.defineProperty (<anonymous>)
})
// babel.config.js
module.exports = {
presets: ['module:@react-native/babel-preset']
}
// jest.config.js
module.exports = {
preset: 'react-native',
testRegex: '/*\\.test\\.tsx?$',
transform: {
'.m?(js|ts)x?$': 'babel-jest',
},
transformIgnorePatterns: [],
moduleNameMapper: {
'\\.(css|less|sass|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'react-native/jest/assetFileTransformer.js',
'estree-walker': '<rootDir>/node_modules/estree-walker/src/index.js',
periscopic: '<rootDir>/node_modules/periscopic/src/index.js',
'is-reference': '<rootDir>/node_modules/is-reference/src/index.js',
}
} Thanks for helping. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
? Please provide much more info: https://mdxjs.com/community/support/ |
Beta Was this translation helpful? Give feedback.
-
Welcome @zfben! 👋 Jest needs to be configured to support ESM. https://mdxjs.com/migrating/v2/#esm Where possible I'd recommend migrating to |
Beta Was this translation helpful? Give feedback.
Welcome @zfben! 👋
Sorry you ran into a spot of trouble.
Jest needs to be configured to support ESM. https://mdxjs.com/migrating/v2/#esm
The Jest ESM guide and the ESM guide by Sindre linked in the trouble shooting section explain this more on how to configure and known bugs in Jest.
Where possible I'd recommend migrating to
node:test
for a fast and light weight testing experience https://nodejs.org/api/test.htmlor
vitest
for a Jest compatible test library https://vitest.dev/Both
node:test
andvitest
have strong ESM support.