I am new at angular I have a service that calls HTTP post requests with some parameters. Now I want to test that service function in angular.
My service part is
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class GetProviderService{
providersData: any;
constructor(private http: HttpClient) {
}
getProviders(param: any): any{
var json = JSON.stringify(param);
const myHeader = new HttpHeaders().set('content-type','application/json');
this.http.post<any>(url, json, {headers: myHeader}).subsribe(data=> {
this.providerData = data;
return this.providerData;
}),
(erorr) => {
window.alert("error");
return null;
}
}
now I want to cover getProviders functions with error subscribe and error. How can I do this?
Thank you in advance.