Currently, I am trying to test the following .ts file:
create(entityResourceID, params: any): Observable <any>{
const url = `${this.apiUrl}/${entityResourceID}/assignee`;
return this.http.post(url, params).pipe(
map(() => { this.toaster.success('Successfully Asssigned Email'); }),
catchError((error) => [
console.error(error),
this.toaster.error('Failed Assigning Email')
])
);
}
However, I encountered an error stating that .pipe is not a function
Here is my current test spec.ts file setup:
describe('create', () => {
it('should return a valid url', () => {
const spy = jest.spyOn(mockHttpClient, 'post').mockReturnValue('test');
const result = component.create(testEntityID, {});
expect(spy).toBeCalledWith('entities/url/assignee', {});
expect(result).toStrictEqual('test');
});
});
I am aware that testing has become challenging because of the return type being an Observable. Can anyone guide me on how I can return an Observable from my spy in order to efficiently test both cases?