I try to understand how to test this function. From (err)=>{ line,
it's showing as an uncovered statement.
service.ts
Deletevote(inp) {
console.log(inp);
return this.http.post(environment.apiUrl + '/api/reset/abc', inp).pipe(
catchError((err) => {
console.log('error caught in service');
console.error(err);
return throwError(err);
})
);
}
I have created this test case for positive flow, but err part is still not covered. Please guide me about how to create the error.
service.spec.ts
const Mockcolor = 'green';
const MockGen = 'male';
it('submitnominGreen', () => {
service.Deletevote(DeleteObj).subscribe((posts) =>{
expect(posts).toEqual([Mockcolor,MockGen], 'should check mock data');
});
const req = httpTestCtrl.expectOne(environment.apiUrl + '/api/reset/abc');
expect(req.request.method).toBe('POST');
expect(req.cancelled).toBeFalsy();
req.flush([Mockcolor,MockGen])
});
it('submitnominGreen', () => { service.Deletevote(DeleteObj).subscribe((posts) =>{ expect(posts).toEqual([Mockcolor,MockGen], 'should check mock data'); }); const req = httpTestCtrl.expectOne(environment.apiUrl + '/api/reset/abc'); expect(req.request.method).toBe('POST'); expect(req.cancelled).toBeFalsy(); req.flush([Mockcolor,MockGen]) });
I tried this but still it's not covering error part. Please guide for errors part now – Zymase