What does 1x 3x mean, etc. in karma code coverage report in Angular2 Unit testing?

I am new to unit testing in Angular2. I got setup karmawith code coverage along with angular-cli. I ran the ng-test command and opened a code coverage report. I saw 1x, 3xetc. Together with the code line numbers in this coverage report. Please find an image of my coverage report.

enter image description here

Here is my test code 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!');
  }));
});

I did not understand the importance of this 1x,2x,3x, etc. in my code report. Please help me in understanding the importance of this.

+4
source share
1 answer

, .

title:

: expect(app).toBeTruthy();

: expect(app.title).toEqual('app works!');

-: expect(compiled.querySelector('h1').textContent).toContain('app works!');

, 3 .

+7

Source: https://habr.com/ru/post/1667324/


All Articles