Function to be tested
changeIva(idTax: number, index: number): void {
this.documentService.getTaxById(idTax).subscribe(tax => {
if (tax.codigo === 'ISE') this.openModal(index);
});
}
How far I've come
it('should test whether the tax is exempt or not', () => {
const taxMockSuccess = taxMock[0];
const idTax = 106;
const index = 1;
const modalOpenSpy = spyOn(component['modal'], 'open');
const documentServiceSpy = spyOn(documentService, 'getTaxById').and.returnValue(
of({ taxMockSuccess })
);
component.changeIva(idTax, index);
expect(documentServiceSpy).toBeCalledWith(idTax);
expect(modalOpenSpy).toBeCalled();
});
I need help, I don't know how to test this IF within the subscribe