title: Testing errors in Angular 5 Unit Testing after subscribtion
body: <p>I have the following function in my Angular 5 controller on which i want to do UnitTesting using karma.</p>
  
  <pre><code>this.search.getFirstSearch().subscribe(data =&gt; {
        this.processSchool = data.search3,
          error =&gt;&lt;any&gt; this.errorMessage,
          ()=&gt;{
            if(this.errorMessage ===''){
      console.log('abc')
            }else{
              console.log('xxxx')
            }
          }
  
      });
  </code></pre>
  
  <p>Unfortunately, I have difficulties testing the function error statement. I tried the following codes, but as far as I see from generated covrage, this part is not covered.</p>
  
  <pre><code>it('should simulate error 1  ', () =&gt; {
      fixture.detectChanges();
  
      const searchService = fixture.debugElement.injector.get(SearchService);
      const mockCall= spyOn(searchService, 'getFirstSearch').and.returnValue(Observable.throw({status: 404}));
  
      //call method 
      comp.processData();
  
    });
  
    it('should simulate error 2  ', () =&gt; {
  
      const searchService = fixture.debugElement.injector.get(SearchService);
      const mockCall= spyOn(searchService, 'getFirstSearch').and.returnValue(Observable.throw({message: ""}));
  
      //call method 
      comp.processData();
    });
  
  
  
    it('should simulate error 3 ', async(() =&gt; { fixture.detectChanges();
      const searchService = fixture.debugElement.injector.get(SearchService);
      let    error404 = {status: 404};
      backend.connections.subscribe((connection: MockConnection) =&gt; {
        connection.mockError(error404 as any as Error);
      });
  
      comp.processData();
    }));
  
  
    ////added test
  
    it('should simulate error 4 ', () =&gt; { fixture.detectChanges();
  
      const searchService = fixture.debugElement.injector.get(SearchService);
      const mockCall= spyOn(searchService, 'getFirstSearch').and.returnValue(
        new ErrorObservable('TwainService test failure'))
  
      comp.processData();
  
  
    });
  
    it('should simulate error 5', () =&gt; { fixture.detectChanges();
  
      const searchService = fixture.debugElement.injector.get(SearchService);
      const mockCall= spyOn(searchService, 'getFirstSearch').and.returnValue(Observable.throw({message: ""}));
  
      comp.processData();
  
    });
  </code></pre>
  
  <p>From the generated report, the error part is not covered. What am I missing?</p>
  
  <p><a href="https://i.stack.imgur.com/2yXxz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2yXxz.png" alt="enter image description here"></a></p>