我有一个 Angular 6 应用程序,我正在使用 karma + jasmine 来运行我的测试。但是当我运行
ng test
时,我收到以下错误:
错误 TS2688 中的错误:找不到“jest”的类型定义文件。
有人知道如何解决这个问题吗?
我没有意识到,在我的
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"
]
}
这个改变解决了我的问题。
截至 2023 年 8 月,如果您使用的是最新版本的
@testing-library/jest-dom
,您所需要做的就是删除 @types/testing-library_jest-dom
。