In my angular application, I have a REST API call which returns me a Blob data which is eventually opened in a new tab. I am trying to create a mock Blob object in my jasmine testcase and spyon the service call and return the Blob. I am not able to assign it to the response and cannot validate my mock blob.
spec.ts
it('should call open doc ', () => {
spyOn<any>(component['docService'], 'getDoc');
component['getDOC']('mypdf');
let obj = Object({ responseType: 'blob' });
component['docService']['getResponse'] = obj;
expect(component['docServicee']['getDoc']).toHaveBeenCalled();
});
component.ts
public getDOC(file: string): void {
this.docService.getDoc('mypdf);
this.docService.getResponse.subscribe((response) => {
if (response) { // Test case not covered
// open the file
}
});
}
DocService.ts
public getDoc(val): void {
apiEndpointcall.subscribe({
next: (res: Blob) => {
},
error: (error: Error) => {
}
});
}