title: How to test an Observable that depends on another and assert between subscriptions
body: <p>I am writing jasmine unit tests for an AuthenticationService. I need to test that the logout method clears the user authentication. In doing so, I require to:</p>
  
  <ol>
  <li>make an http call through authService.login()</li>
  <li>assert that the user is authenticated</li>
  <li>make an http call through authService.logout()</li>
  <li><p>assert that the user is no longer authenticated</p>
  
  <pre><code>describe('logout', () =&gt; {
  it('should clear user authentication', fakeAsync(() =&gt; {
    authenticationService.login(loginContext)
      .subscribe(() =&gt; {
        expect(authenticationService.isAuthenticated()).toBe(true);
  
        authenticationService.logout()
          .subscribe(() =&gt; {
            expect(authenticationService.isAuthenticated()).toBe(false);
            expect(authenticationService.credentials).toBeNull();
            expect(sessionStorage.getItem(credentialsKey)).toBeNull();
            expect(localStorage.getItem(credentialsKey)).toBeNull();
          });
    });
  
    const logoutRequest = httpMock.expectOne(`${environment.apiSettings.serviceUrl}${logoutApi}`);
    expect(logoutRequest.request.method).toEqual('POST');
    logoutRequest.flush(true);
  }));
  </code></pre></li>
  </ol>
  
  <p>As you can see below, httpMock doesn't like this at all. I have the feeling that I need to somehow use flatMap in this circumstance, but haven't been able to get that working either. Any ideas?</p>
  
  <p><a href="https://i.stack.imgur.com/q8HbL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q8HbL.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/4k7O3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4k7O3.png" alt="enter image description here"></a></p>