title: How to test http.post request with parameters in angular 9?
body: <p>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.</p>
  <p>My service part is</p>
  <pre><code>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&lt;any&gt;(url, json, {headers: myHeader}).subsribe(data=&gt; {
     this.providerData = data;
     return this.providerData;
     }),
     (erorr) =&gt; {
       window.alert(&quot;error&quot;);
       return null;
     }
  }
  
  </code></pre>
  <p>now I want to cover getProviders functions with error subscribe and error.
  How can I do this?</p>
  <p>Thank you in advance.</p>