Angular CLI 6,ng test无法工作

27

我刚刚将我的Angular项目更新到了Angular 6。

使用命令运行测试时,ng build和ng serve正常工作:

ng test

我得到了输出:

Schema validation failed with the following errors:
Data path "" should have required property 'tsConfig'.

tsconfig.json:

{
"compilerOptions": {
"baseUrl": "",
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
  "es2016",
  "dom"
],
"mapRoot": "./",
"module": "es2015",
"moduleResolution": "node",
"outDir": "../dist/out-tsc",
"sourceMap": true,
"target": "es5",
"typeRoots": [
  "../node_modules/@types"
]
}
}

我做错了什么?

3个回答

30

我解决了它。不知何故,当我将项目升级到 Angular 6 时,在 angular.json 的 test -> options 下缺少了 tsConfig 键。


根据其他答案,这是tsConfig的默认设置 => "tsConfig": "src/tsconfig.json"。 - MortimerCat

21

针对我

  1. 文件路径: angular.json

  2. JSON节点路径: projects->{{yourProjectName}}->architect->test->options

  3. 添加节点: "tsConfig": "src/tsconfig.json"


1
这个答案也是正确的,但是描述得不够详细。所以有点难理解。 - ip_x
是的...在构建和测试选项中都有tsConfig...你需要将其添加到测试选项中。 - Rohit Kumar
难道不应该添加 src/tsconfig.spec.json 文件到 test 部分吗? - Florian Leitgeb

0
我曾经遇到过这个问题,但后来发现是由于在 tsconfig.spec.json 中添加了 polyfills.ts 导致的。Polyfills 导入了 core-js/es7/reflect,而我在 src/test.ts 中也做了同样的事情。将 src/test.ts 中的导入移除后,问题得以解决。

你到底删掉了哪一行? - Soumya Gangamwar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接