错误 TS2688 中的错误:找不到“jest”的类型定义文件

问题描述 投票:0回答:2

我有一个 Angular 6 应用程序,我正在使用 karma + jasmine 来运行我的测试。但是当我运行

ng test
时,我收到以下错误:

错误 TS2688 中的错误:找不到“jest”的类型定义文件。

有人知道如何解决这个问题吗?

angular jasmine angular6 angular-cli karma-runner
2个回答
8
投票

我没有意识到,在我的

tsconfig.spec.json
中,我在
jest
节点中使用了
jasmin
而不是
types
。另外,我缺少配置。

所以,我已经改变了:

{
  "extends": "./tsconfig.es5.json",
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "outDir": "../out-tsc/spec",
    "module": "commonjs",
    "target": "es6",
    "baseUrl": "",
    "types": [
      "jest",
      "node"
    ]
  },
  "files": [
    "**/*.spec.ts"
  ]
}

对此:

{
  "extends": "./tsconfig.es5.json",
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "outDir": "../out-tsc/spec",
    "module": "commonjs",
    "types": [
      "jasmine",
      "node"
    ]
  },
  "files": [
    "test.ts",
    "polyfills.ts"
  ],
  "include": [
    "**/*.spec.ts",
    "**/*.d.ts"
  ]
}

这个改变解决了我的问题。


0
投票

截至 2023 年 8 月,如果您使用的是最新版本的

@testing-library/jest-dom
,您所需要做的就是删除
@types/testing-library_jest-dom

© www.soinside.com 2019 - 2024. All rights reserved.