Ric*_*cha 6 jasmine karma-runner angular-cli angular angular6
我有一个 angular 6 应用程序,我正在使用 karma + jasmine 来运行我的测试。但是当我运行时,ng test我收到以下错误:
错误 TS2688 中的错误:找不到“jest”的类型定义文件。
有谁知道如何解决这个问题?
may*_*513 21
截至 2023 年 8 月,如果您使用的是最新版本的@testing-library/jest-dom,您所需要做的就是删除@types/testing-library_jest-dom。
我没有意识到tsconfig.spec.json我在使用jest而不是jasmin在typesnode.js 中。另外,我缺少配置。
所以,我已经改变了:
{
"extends": "./tsconfig.es5.json",
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"outDir": "../out-tsc/spec",
"module": "commonjs",
"target": "es6",
"baseUrl": "",
"types": [
"jest",
"node"
]
},
"files": [
"**/*.spec.ts"
]
}
Run Code Online (Sandbox Code Playgroud)
对此:
{
"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"
]
}
Run Code Online (Sandbox Code Playgroud)
这个改变解决了我的问题。