Cypress: Clashing types with Jest

Viewed 2458

I am facing the problem the types in Cypress and Jest clashing (such as "expect").

example.spec.ts

expect(value).toBe(0) // Property 'toBe' does not exist on type 'Assertion'.

I edited tsconfig.json in the following way, but it did not solve.

Here's my tsconfig

{
  "compilerOptions": {
    "target": "ES2018",
    "module": "ESNext",
    "moduleResolution": "Node",
    "resolveJsonModule": true,
    "lib": [
      "ESNext",
      "ESNext.AsyncIterable",
      "DOM"
    ],
    "esModuleInterop": true,
    "allowJs": true,
    "sourceMap": true,
    "strict": true,
    "noEmit": true,
    "experimentalDecorators": true,
    "baseUrl": ".",
    "paths": {
      "~/*": [
        "./*"
      ],
      "@/*": [
        "./*"
      ]
    },
    "types": [
      "@nuxt/types",
      "@nuxtjs/axios",
      "@types/node",
      "nuxt-i18n",
      "jest"
    ]
  },
  "exclude": [
    "node_modules",
    ".nuxt",
    "dist"
  ]
}
1 Answers

I solved the problem with the following:

./tsconfig.json

{
  "compilerOptions": {
    "isolatedModules": true,
    ...
  },
  "exclude": ["cypress/**/*"]
}

./cypress/tsconfig.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "isolatedModules": false
  },
  "include": [
    "../node_modules/cypress"
  ]
}
Related