title: How to unit test nested subscribe methods in Angular?
body: <pre><code>MethodToBeTested() {
    this.serviceA.methodA1().subscribe((response) =&gt; {
     if (response.Success) {
       this.serviceA.methodA2().subscribe((res) =&gt; {
          this.serviceB.methodB1();
        })
      }
    });
  }
  </code></pre>
  
  <p>Here is  the scenario.</p>
  
  <p>Things to test:</p>
  
  <ol>
  <li><code>serviceA.methodA1().</code> was called.</li>
  <li>if response.Success then check if <code>serviceA.methodA2()</code> was called</li>
  <li>check if <code>serviceB.methodB1()</code> was called when <code>serviceA.methodA2()</code> received value.</li>
  </ol>
  
  <p>first, one is easy to test.</p>
  
  <pre><code>let spy = spyOn(serviceA, 'methodA1');
  expect(spy).toHaveBeenCalled();
  </code></pre>
  
  <p>But does one test 2 and 3?</p>
  
  <pre><code> let spy= spyOn(serviceA, 'methodA1').and.returnValue({subscribe: () =&gt; {success:true}});
  subject.MethodToBeTested();
  </code></pre>
  
  <p>something like that? </p>