how to setup expo with jest and typescript

I am trying to use typescript and jest with expo (jest will be in js or ts-jest), and no matter what I do I keep getting this error when i try running jest:

type ErrorHandler = (error: mixed, isFatal: Boolean) => void;

SyntaxError: Unexpected identifier 'ErrorHandler'

  at Runtime.createScriptFromCode (node_modules/.pnpm/jest-runtime@29.5.0/node_modules/jest-runtime/build/index.js:1495:14)

I tried every way i found online and even tried my best with chatgpt and I couldn’t fix it, I looked at the docs for both jest, rn, and expo and couldn’t find a solution for this error. I tried ignoring it in the jest.config.js and that also didn’t work

for my jest.config.js and babel.config.js they changed so many times in so many ways but i will paste what i currently have:

β”‚ File: .\babel.config.js
1 β”‚ module. Exports = function(api) {
2 β”‚ api.cache(true);
3 β”‚ return {
4 β”‚ presets: [β€˜babel-preset-expo’],
5 β”‚ };
6 β”‚ };

β”‚ File: .\jest.config.js
1 β”‚ module.exports = {
2 β”‚ preset: β€˜jest-expo’,
3 β”‚ transformIgnorePatterns: [
4 β”‚ β€˜node_modules/(?!(jest-)?react-native|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(
β”‚ nent)?/.|react-navigation|@react-navigation/.|@unimodules/.|unimodules|sentry-expo|native-base|(@react-nativ
β”‚ e/polyfills|@react-native/polyfills/.
5 β”‚ ],
6 β”‚ setupFilesAfterEnv: [β€˜@testing-library/jest-native/extend-expect’],
7 β”‚ };

Okay so the issue is in the path I am giving to transformIgnorePatterns.

since i am using pnpm i needed to specify .pnpm after node_modules

1 Like

Thanks for following up with your solution!

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.