Test suite failed to run, SyntaxError: Unexpected identifier
PaulDuong1 opened this issue · comments
Hi, I was blocked by this error after I upgrade react native, jest and enzyme.
Here is an example:
FAIL src/features/orders/screens/order-screen/order-rating/order-rating-preview/tests/OrderRatingPreview.spec.js
● Test suite failed to run
rootPath/node_modules/@react-native/polyfills/error-guard.js:14
type ErrorHandler = (error: mixed, isFatal: boolean) => void;
^^^^^^^^^^^^
SyntaxError: Unexpected identifier
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
at Object.<anonymous> (node_modules/react-native/jest/setup.js:439:6)
Test Suites: 606 failed, 606 total
Tests: 0 total
Snapshots: 0 total
Time: 22.46 s
setup.ts
import 'react-native-gesture-handler/jestSetup';
import { configure, mount, render, shallow } from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import { NativeModules } from 'react-native';
configure({ adapter: new Adapter() });
Environment
"react": "17.0.1",
"react-native": "0.64.2",
"jest": "^27.0.5",
"jest-circus": "^26.6.3",
"jest-expo": "^42.1.0",
"jest-junit": "^12.0.0",
"jest-watch-typeahead": "^0.6.4",
"enzyme": "^3.11.0",
"enzyme-to-json": "^3.6.2",
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.3",
"jest": {
"preset": "jest-expo",
"cacheDirectory": "./cache",
"coveragePathIgnorePatterns": [
"index.js",
"./src/globals/*"
],
"moduleFileExtensions": [
"ts",
"tsx",
"jsx",
"js"
],
"testPathIgnorePatterns": [
"./e2e",
"./node_modules/",
"./ios/",
"./android"
],
"setupFiles": [
"./jest/setup.js"
],
"setupFilesAfterEnv": [
"./jest/setupAfterEnv.js"
],
"snapshotSerializers": [
"enzyme-to-json/serializer"
],
"collectCoverageFrom": [
"src/**/*.{js,jsx,ts,tsx}",
"!src/**/*.{stories,e2e,spec,d}.*"
],
"coverageDirectory": "./coverage/",
"collectCoverage": false,
"watchPlugins": [
"jest-watch-typeahead/filename",
"jest-watch-typeahead/testname"
]
},
"jest-junit": {
"outputDirectory": "./coverage/jest",
"outputName": "results.xml"
},
I know this may not an enzyme problem, but I really need help to fix it and the issue section of Jest is not friendly with asking question.
Please leave your idea, I appreciate!
I'd suggest using StackOverflow for general questions that are not bug reports.
An update, if you meet similar problem, you need tune "transformIgnorePatterns" in your jest configuration.
e.g.
"transformIgnorePatterns": [
"node_modules/(?!((jest-)?react-native(-.*)?|@react-native(-community)?)/)"
]