Im trying to configure an unit test for my website with Jest and I can't get it to work correctly. I've tried some of the solutions suggested by the ts-jest documentation but it still hasn't worked. Im not using Babel unless it's really necessary.
This is the link to the project: https://github.com/Kirarizinho02/AquaLink
This is what the jest.config.ts looks like:
import type { JestConfigWithTsJest } from 'ts-jest'
const config: JestConfigWithTsJest = {
collectCoverage: true,
coverageDirectory: 'coverage',
coverageProvider: 'v8',
preset: 'ts-jest/presets/default-esm',
testPathIgnorePatterns: ['/node_modules/'],
transform: {},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1'
},
testEnvironment: 'node'
}
export default config
This is the tsconfig.json:
{
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.node.json"
}
],
"compilerOptions": {
"jsx": "react",
"isolatedModules": true,
"esModuleInterop": true,
"baseUrl": ".",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"target": "ESNext",
"paths": {
"@/*": ["./src/*"]
}
}
}
And this is the error:
import { LoginUsers } from "@/components";
^^^^^^
SyntaxError: Cannot use import statement outside a module
I've tried using testEnvironment: 'jsdom', but it didn't work.
I've tried changing my "type": "module" to "type": "commonjs" only to find the same error.
ts-jest/presets/defaultwork instead?