I have called a function inside ngOnInit,
ngOnInit() {
this.isSubscribable();
}
I wan to do unit testing for this ngOnInit like this:
it('Check isSubscribable is called from ngOnInit', async(async() => {
spyOn(component, 'isSubscribable').and.callThrough();
fixture.detectChanges();
await fixture.whenStable();
expect(component.isSubscribable).toHaveBeenCalled();
}))
This is not working. I need some help on this.
What if you try like this ?
it('Check isSubscribable is called from ngOnInit', () => {
const spySubscribable = spyOn(component, 'isSubscribable');
component.ngOnInit();
expect(spySubscribable).toHaveBeenCalled();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With