import { Component, OnInit } from '@angular/core';
import { Title } from '@angular/platform-browser';
@Com(I)ponent({
selector: 'app-fruit-cake',(E)
templateUrl: './fruit-cake.component.html',
styleUrls: ['./fruit-cake.component.scss'],
})
expo(E)rt class FruitCakeComponent {
constructor(private _title: Title) {
_title.setTitle('Cake');
}
}
我的代码覆盖率报告显示(E):否则未使用路径。 (I):如果未采取措施。 在import语句和装饰器的上下文中是什么意思? 因此,在我的任何测试中,我的代码覆盖率均未达到100%。 我该如何纠正?
答案 0 :(得分:16)
对于Angular 6,看来您需要像这样"sourceMap": true
到test
:
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "test/test.ts",
"karmaConfig": "./karma.conf.js",
"sourceMap": true,
"polyfills": "src/polyfills.ts",
"tsConfig": "test/tsconfig.spec.json",
"scripts": [],
"styles": [],
"assets": [
"src/assets"
],
"codeCoverageExclude": []
}
答案 1 :(得分:4)
我必须删除:
--sourceMap=false
以前,我已添加此功能以帮助诊断其他问题。因此,我在 package.json 中的测试脚本看起来像这样:
"test": "ng test --code-coverage --sourceMap=false"
我将其更改为:
"test": "ng test --code-coverage"
然后,我所有的代码覆盖率都开始正确报告。您可能还需要在 package.json 中验证您的 devDependencies 。我正在使用 Angular 6 ,所以它们看起来像这样:
"devDependencies": {
"@angular/compiler-cli": "^6.0.3",
"@angular-devkit/build-angular": "~0.6.8",
"typescript": "~2.7.2",
"@angular/cli": "~6.0.8",
"@angular/language-service": "^6.0.3",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1"
}