Ise*_*mar 11 javascript unit-testing istanbul karma-coverage angular
我是Angular的单元测试的新手.我得到了karma代码覆盖率的设置angular-cli.我运行了命令ng-test并打开了代码覆盖率报告.我看到了1x,3x等一起在覆盖报告我的代码行数.请找到我的报道图像.
这是我的测试用例代码 app.component.spec.ts
/* tslint:disable:no-unused-variable */
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
});
});
it('should create the app', async(() => {
let fixture = TestBed.createComponent(AppComponent);
let app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
it(`should have as title 'app works!'`, async(() => {
let fixture = TestBed.createComponent(AppComponent);
let app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('app works!');
}));
it('should render title in a h1 tag', async(() => {
let fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
let compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('app works!');
}));
});
Run Code Online (Sandbox Code Playgroud)
我不明白1x,2x,3x我的代码报告中那个等等的重要性.请帮助我了解其重要性.
eko*_*eko 15
它表示该行已执行的次数.
根据你的代码,让我们来看看你的title领域:
它首先被执行: expect(app).toBeTruthy();
第二: expect(app.title).toEqual('app works!');
第三: expect(compiled.querySelector('h1').textContent).toContain('app works!');
所以这就是为什么它在左边说3x.