I'm trying to understand how to fix the following error using Jest in my unit tests in NodeJS.
The test run with this command "test": "NODE_ENV=test jest spec/* -i --coverage --passWithNoTests",
I'm also using babel and this is my config
{
"presets": [["@babel/env", { "targets": { "node": "current" } }]],
"plugins": [
"@babel/plugin-syntax-dynamic-import",
["babel-plugin-inline-import", { "extensions": [".gql"] }],
["@babel/plugin-proposal-decorators", { "legacy": true }]
]
}
In package.json I have this
"jest": {
"verbose": true,
"collectCoverageFrom": [
"spec/**/*.js"
]
},
I tried several guides online but cannot find a solution to this
If you have .babelrc try to rename it to babel.config.js
Source: https://babeljs.io/docs/en/configuration#whats-your-use-case
but also this (there's more in the discussion) Jest won't transform the module - SyntaxError: Cannot use import statement outside a module