I am writing an httpGet call to get images as blob here is the call:
public getImage(link: string): Observable<any> {
return this.http.get<any>(this.createUrl('storage/' + link ), { headers: this.createHeaders(),
responseType: 'blob' as 'json' });
}
This is my unittest:
it('should get the images', () => {
let response = {};
service.getImage('testImage').subscribe(
data => {
expect(data).toEqual(response, 'should return expected data');
const req = httpMock.expectOne(`https://api/storage/testImage`);
expect(req.request.method).toBe('GET');
req.flush(response);
});
});
When I write the test like above I get the error: "Expected no open requests, found 1:"
If I put this code:
const req = httpMock.expectOne(https://api/storage/testImage
);
expect(req.request.method).toBe('GET');
req.flush(response);
outside of the subscription I get the error : "Automatic conversion to Blob is not supported for response type."
Does someone knows how to fix this?
I changed the response to blob type:
let response = new Blob();
and it works like a charm 😋
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