I would like to test if one of my helper functions are being called in the http service layer but I get a failed test. I am new to jest so please tell me know what am I doing wrong
Service Layer
public customerUpload(
file: Blob,
name?: string): Observable<CustomerResponse> {
if (name!== '') {
parameters = addQueryPara(name, 'name');
}
return this.http.post(file, parameters)
)
I want to check if I called CustomerUpload with name, it should call addQueryPara
My Spec file Test
import * as helper from 'app/shared/helper.ts';
describe('customerService', () => {
let service: customerService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientModule],
});
service = TestBed.inject(customerService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
describe('when customer is called', () => {
beforeEach(() => {
const response = getMockResponse();
jest.spyOn(service, 'customerUpload').mockReturnValue(of(response) as any);
});
it('should add http params', () => {
service.customerUpload(new Blob(), 'learn');
expect(jest.spyOn(helper, 'addQueryPara')).toHaveBeenCalledTimes(1); // This is failing
});
});
});
addQueryPara is failing. How can I make sure if I pass a parameter, it calls addQueryPara?