title: [Angular7][Jest] How to test a MergeMap?
body: <p>I need your help :)</p>
  
  <p>I used angular 7 and Rxjs. For the test, I used Jest.</p>
  
  <p>I have my component that use a MergeMap between 2 httpClient like that : </p>
  
  <pre><code>addPost() {
    this.postService.createPost(post).pipe(
      mergeMap( (response) =&gt; { return this.postService.getPost(response.headers.get('Location'));} )
    ).subscribe(
      (post) =&gt; {
        this.content =""; this.postService.addingPostToArray(post);
      }, (error) =&gt; {
        //todo
      }
    );
  }
  </code></pre>
  
  <p>And my PostService :</p>
  
  <pre><code>createPost(post:Post) {
   return this.httpClient
     .post('http://localhost:8080/posts', {post: post}, {observe:  'response'}); 
  }
  
  getPost(url: any) {
     return this.httpClient.get&lt;Post&gt;(url);
  }
  </code></pre>
  
  <p>And I created test to my component like that : </p>
  
  <pre><code>it('should test addPost OK', () =&gt; {
  postService = TestBed.get(PostService);
  spyOn(postService, 'createPost').and.returnValue(of('test'));
  spyOn(postService, 'getPost').and.returnValue(of('test'));
  
  component.addPost();
  
  expect(postService.createPost).toHaveBeenCalled();
  expect(postService.getPost).toHaveBeenCalled();
  </code></pre>
  
  <p>});</p>
  
  <p>But the problem is that my getPost is never called.</p>
  
  <pre><code>expect(spy).toHaveBeenCalled()
  
  Expected spy to have been called, but it was not called.
  
    131 |
    132 |     expect(postService.createPost).toHaveBeenCalled();
  &gt; 133 |     expect(postService.getPost).toHaveBeenCalled();
  </code></pre>
  
  <p>How can I test the mergeMap ? </p>
  
  <p>I hope that my explanations isn't too weird :)</p>
  
  <p>Thanks for your help ;)</p>