I wan jest to do unit tests with jest and typescrip/react but my test fails because says there are syntax errors in my imports. This is my jest.cinfig.ts file and babelrc file
{
"env": {
"test": {
"presets": [
[
"@babel/preset-env",
{
"corejs": { "version": 3, "proposals": true },
"useBuiltIns": false,
"targets": {
"node": "current"
}
}
],
[
"@babel/preset-react",
{
"runtime": "automatic"
}
],
"@babel/preset-typescript"
],
"plugins": [
"@babel/plugin-transform-runtime",
["@babel/proposal-class-properties", {}, "babel-proposal-class-properties"],
"@babel/plugin-transform-classes"
]
}
}
}
<pre>import type {Config} from 'jest';
const config: Config = {
clearMocks: true,
collectCoverage: true,
collectCoverageFrom: [
'**/src/services/**/*.{ts,tsx}',
'**/src/components/**/*.ts',
'**/src/contexts/**/*.ts',
'**/src/hooks/**/*.ts',
'**/src/utils/**/*.ts',
'!**/src/components/**/messages.ts',
'!**/__snapshots__/*.snap',
'!**/__mocks__/**/*',
'!**/__fixtures__/**/*',
'!**/mocks/**/*',
'!**/mock.js',
'!**/mocks.js',
],
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: ['/node_modules/'],
moduleFileExtensions: [
"js",
"mjs",
"cjs",
"jsx",
"ts",
"tsx",
"json",
"node"
],
roots: ['<rootDir>'],
testEnvironment: 'jsdom',
transform: {
'^.+\\.[t|j]sx?$': 'babel-jest',
'^.+\\.(ts?)$': 'ts-jest',
'.+\\.(css|styl|less|sass|scss)$':
'<rootDir>/node_modules/jest-css-modules-transform',
},
}
export default config
What I have tried:
I trued deleten cache and adding the ignore pattern in ts config file