1

I have the following code, comp:

ngOninit() {
  window.addEventListner('oreantationChange' () =>  {
    this.sideNavbar();
  });
}

Here I want to cover the above code and the following are my changes, spec:

it ('-----',() => {
  spyOn(window,'addEventListner');
  window.addEventListner('oreantationChange' () =>  {
     expect(component.sideNavbar).toHaveBeenCalled()
  });
}

But the above test is not getting covered.

Can anyone please suggest me help.Thanks.

Ashish Kamble
  • 2,555
  • 3
  • 21
  • 29
learner
  • 357
  • 1
  • 6
  • 16
  • Shouldn't `oreantationChange` be `orientationChange`? https://developer.mozilla.org/en-US/docs/Web/API/Window/orientationchange_event – uminder Aug 28 '19 at 09:26

1 Answers1

1

Beside changing oreantationChange to orientationChange, rewrite the test as follows.

it ('-----', () => {
    spyOn(component, 'sideNavbar');
    window.dispatchEvent(new Event('orientationChange'));

    expect(component.sideNavbar).toHaveBeenCalled();
});
uminder
  • 23,831
  • 5
  • 37
  • 72