title: Angular/Karma/Jasmine unit test fails silently when error is thrown
body: <p>I have Karma/Jasmine unit test for Angular interceptor intercept method which returns rxjs Observable. If there is some error in success callback unit test will appear as passed even though it should fail. Code:</p>
  
  <p>method under test:</p>
  
  <pre><code>intercept(
    request: HttpRequest&lt;any&gt;,
    next: HttpHandler
  ): Observable&lt;HttpEvent&lt;any&gt;&gt; {
    ...
  
    return next.handle(req);
  }
  </code></pre>
  
  <p>test:</p>
  
  <pre><code>it("some test desc", () =&gt; {
    const headers = ...
    const request = new HttpRequest('GET', '/test', '', { headers });
  
    const next = jasmine.createSpyObj('HttpHandler', ['handle']);
    const errorResponse = new HttpErrorResponse({
      status: 401,
      error: 'SOME_ERROR_CODE'
    });
  
    next.handle.and.returnValue(throwError(errorResponse));
  
    console.log('before');
    interceptor.intercept(request, next).subscribe(
      () =&gt; fail('Observable should resolve with error.'),
      (res: HttpErrorResponse) =&gt; {
        console.log('in');
        throw new Error('some error happened here');
        expect(res).toBe(errorResponse);
      }
    );
  
    console.log('after');
  });
  </code></pre>
  
  <p>I can fix this by calling done at the end of my error callback as describe <a href="https://angular.io/guide/testing#service-tests" rel="nofollow noreferrer">here</a>, but I don't understand why is it necessary since my code is executed synchronously (due to the rxjs throwError using queueScheduler) which can be confirmed by the order in which logs are executed (before, in, after).</p>