Dan*_*iel 0 karma-jasmine angular
当运行我的测试时,ng test我收到此错误:
C:/.../src/app/my/my.component.spec.ts (111,27) 中出现错误:找不到名称“DebugElement”。
在其他 SO 帖子(例如这篇文章)中,推荐的解决方案是将其添加"lib": ["dom"]到和文件compilerOptions中,但对我来说,该解决方案不起作用,我已经在数组中了,如您在此处看到的:tsconfig.jsontsconfig.spec.json"dom""lib"
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
Run Code Online (Sandbox Code Playgroud)
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/spec",
"baseUrl": "./",
"module": "commonjs",
"target": "es5",
"types": [
"jasmine",
"node"
],
"lib": [
"es2017",
"dom"
]
},
"files": [
"test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}
Run Code Online (Sandbox Code Playgroud)
发生错误的行是该函数的第一行:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
Run Code Online (Sandbox Code Playgroud)
我还能缺少什么?
angular/core从as导入它
import { DebugElement } from "@angular/core";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
938 次 |
| 最近记录: |