3

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.

1
  • would a preset of ts-jest/presets/default work instead? Commented Aug 30 at 6:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.