title: Unit testing HttpInterceptor from Angular 4
body: <p>Can you tell me how to test the HttpInterceptor provided by the Angular 4. I have created an interceptor as per the examples but not sure how to test it. Below is my interceptor and I want to test if the custom headers are added and when response status is 401 <code>window.location.href</code> is done.</p>
  
  <pre><code>export class MyInterceptor implements HttpInterceptor {
  
      intercept(req: HttpRequest&lt;any&gt;, next: HttpHandler): Observable&lt;HttpEvent&lt;any&gt;&gt; {
          const headers = new HttpHeaders();
          this.addHeader(headers); // This will add headers
  
          const changedReq = req.clone({ headers: headers });
          return next.handle(req)
              .catch(err =&gt; {
                  if (err instanceof HttpErrorResponse) {
                      switch (err.status) {
                          case 302:
                          case 401:
                              window.location.href = "http//google.com";
                              break;             
                          default:
                              throw new Error(this.getErrorMessage(err));
                      }
                  }
  
                  return Observable.throw(err);
              });
      }
  </code></pre>