Fix SyntaxError: Unexpected token import
Jest cannot out of the box handle es6 code such as imports
-
Install babel-jest and dependencies
npm install --save-dev babel-jest @babel/core @babel/preset-env
-
Add this to .babelrc:
"presets": ["@babel/preset-env"]
Fix ReferenceError: regeneratorRuntime is not defined
This is caused by code using async/await
-
Install @babel/plugin-transform-runtime and @babel/runtime
npm install --save-dev @babel/plugin-transform-runtime @babel/runtime
-
Add this to .babelrc:
"plugins": ["@babel/plugin-transform-runtime"],
Fix Error: connect ECONNREFUSED 127.0.0.1:80
Add this to package.json:
"jest": {
"testURL": "file://test"
},