Cypress:与 Jest 的类型冲突

kus*_*uya 6 typescript jestjs cypress

我面临 Cypress 和 Jest 中类型冲突的问题(例如“expect”)。

\n

示例.spec.ts

\n
expect(value).toBe(0) // Property \'toBe\' does not exist on type \'Assertion\'.\n
Run Code Online (Sandbox Code Playgroud)\n

我按照以下方式编辑了tsconfig.json,但没有解决。

\n\n

这是我的tsconfig

\n
{\n  "compilerOptions": {\n    "target": "ES2018",\n    "module": "ESNext",\n    "moduleResolution": "Node",\n    "resolveJsonModule": true,\n    "lib": [\n      "ESNext",\n      "ESNext.AsyncIterable",\n      "DOM"\n    ],\n    "esModuleInterop": true,\n    "allowJs": true,\n    "sourceMap": true,\n    "strict": true,\n    "noEmit": true,\n    "experimentalDecorators": true,\n    "baseUrl": ".",\n    "paths": {\n      "~/*": [\n        "./*"\n      ],\n      "@/*": [\n        "./*"\n      ]\n    },\n    "types": [\n      "@nuxt/types",\n      "@nuxtjs/axios",\n      "@types/node",\n      "nuxt-i18n",\n      "jest"\n    ]\n  },\n  "exclude": [\n    "node_modules",\n    ".nuxt",\n    "dist"\n  ]\n}\n
Run Code Online (Sandbox Code Playgroud)\n

kus*_*uya 14

我通过以下方法解决了问题:

./tsconfig.json

{
  "compilerOptions": {
    "isolatedModules": true,
    ...
  },
  "exclude": ["cypress/**/*"]
}
Run Code Online (Sandbox Code Playgroud)

./cypress/tsconfig.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "isolatedModules": false
  },
  "include": [
    "../node_modules/cypress"
  ]
}
Run Code Online (Sandbox Code Playgroud)