I have a function that calls another that itself uses a http subscription, and I am having trouble testing it...
MyComponent
id = 1;
myFunct() {
this.myService.delete(this.id);
}
MyService
delete(id) {
this.http.delete(this.myUrl + '/' + id).subscribe()
}
Test
let mockService;
beforeEach(() => {
TestBed.configureTestingModule({
mockService = createSpyObj(['delete']);
imports: ...,
declarations: ...,
providers: [
{provide: MyService, useValue: mockService}
]
}).compileComponents();
fixture = ...;
component = ...;
fixture.detectChanges();
});
it('should test delete', () => {
mockService.delete.and.returnValue({ subscribe: () => {} });
component.myFunct();
expect(mockService.delete).toHaveBeenCalledTimes(1);
});
My test brings back the error:
Cannot read property 'subscribe' of undefined