Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Branches on constructor not covered

I am creating my unit tests with Jasmine and I have a question about the branch covered.

Does anyone know why the code part shows that the branches are not covered as we can see below?

enter image description here

This is the unit test:

describe('MyComponent', () => {
  let component: MyComponent;
  let fixture: ComponentFixture<MyComponent>;
  let myService: MyService;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ MyComponent ],
      imports: [ MaterializeModule, FormsModule, ReactiveFormsModule, HttpModule ],
      providers: [
        MyService,
        FormBuilder
      ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(MyComponent);
    component = fixture.componentInstance;
    slotsService = TestBed.get(MyService);
    fixture.detectChanges();
  });

  function updateForm(name, surname) {
    component.myForm.controls['name'].setValue(name);
    component.myForm.controls['surname'].setValue(name);
  }

  it('should create', () => {
    expect(component).toBeTruthy();
  });
}
like image 623
Marcio M. Avatar asked Apr 04 '17 19:04

Marcio M.


1 Answers

I've had the same issue for months from the moment I upgraded my projects to angular 4. Unfortunately it is a bug with the angular-cli version 1 and angular 4.

This bug is already logged in the angular-cli project: Test-coverage says that coverage is not 100%, but it truly is! #5871. Unfortunately at the moment, this issue is still open.

This is a snapshot from that logged issue, which matches the one you are asking about:

enter image description here

like image 135
Juan Avatar answered Sep 18 '22 21:09

Juan