Jasmine Angular : How to write unit test for anonymous func given as args

Viewed 45
public listenCloseEvt() {
    this.renderer.listen(window, 'close', () => {
      this.showModal = false;
    });
}

I am able to spyOn render.listen but I am unable to reach this.showModal false line on writing unit test.

1 Answers

If you spy on something the implementation details are lost for that object.

To get to the implementation you'll have to callThrough() to the original implementation on your spy.

Instead of:

spyOn(renderer.listen)

use

spyOn(renderer.listen).and.callThrough()

Related