Jest unit test coverage

Viewed 78

I am new to Jest and hoping someone can help me out.

I currently integrated Jest into my Angular application and am trying to get my unit test coverage up.

I see that I have uncovered lines. I have been trying to write a test to cover line 16 - this.hidePlaceHolder(), but it keeps showing as uncovered.

 @HostListener('ngModelChange') hidePlaceHolderOnChange() {
    this.hidePlaceHolder();
  }

describe('HidePlaceholderDirective', () => {
    // const ren: Renderer2;
    // const elem: ElementRef;
    let directive;
    let directiveEl;
    let fixture: ComponentFixture<DirectiveTestComponent>;
    let component;
    beforeEach(() => {
        TestBed.configureTestingModule({
          declarations: [HidePlaceholderDirective, DirectiveTestComponent],
        }).compileComponents();
        fixture = TestBed.createComponent(DirectiveTestComponent);
        component = fixture.componentInstance;
        directiveEl = fixture.debugElement.query(By.directive(HidePlaceholderDirective));
        directive = directiveEl.injector.get(HidePlaceholderDirective);
      });
 
    it('should create an instance', () => {
        expect(directive).toBeTruthy();
    });
    it('should call hidePlaceholder', () => {
    directiveEl.dispatchEvent(new Event('input'));
    expect(directive.hidePlaceHolder).toHaveBeenCalled();
  });
});

0 Answers
Related