title: angular jasmine test with toHaveBeenCalled
body: <p>I'm trying to write a unit test for the following function:</p>
  
  <pre><code>onNextClick() {
      this.toast.clear();
  
      let checkedSubservices = new Array&lt;number&gt;();
      for (let i = 0; i &lt; this.subSevices.length; i++) {
          if (this.subSevices[i].checked) {
              checkedSubservices.push(this.subSevices[i].id);
          }
      }
  
      if (checkedSubservices.length &gt; 0)
      {
          this.bookService.setSubserviceIds(checkedSubservices);
          this.stepService.getNextStepByController(StepControllerNames.AllocationStepController)
              .then((ret: StepControllerReturnInfo) =&gt; {
                  this.goToControllerTarget(ret);
              }).catch((error) =&gt; {
                  // Error
              });
      }
      else
      {
          let options = { positionClass: 'toast-top-center', preventDuplicates: true };
          this.toast.error("Error.", "", options);
      }
  }
  </code></pre>
  
  <p>I want to test that the <code>goToControllerTarget</code> has been called. So I have created the following test:</p>
  
  <pre><code>it('onNextClick a service is checked', fakeAsync(() =&gt; {
      let ret = new ReturnInfo();
  
      let services = new Array&lt;any&gt;();
      services.push({id: 1, title: "Tite 1"});
      services.push({id: 2, title: "Tite 2"});
      services.push({id: 3, title: "Tite 3"});
  
      component.subSevices = services;
      const spy = spyOn(stepService, "getNextStepByController").and.returnValue(Promise.resolve(ret));
      const spy2 = spyOn(component, "goToControllerTarget");
  
      // Test Function
      component.onNextClick();
      tick(0);
  
      expect(spy2).toHaveBeenCalled();
  }));
  </code></pre>
  
  <p>The test fails as the <code>goToControllerTarget</code> function doesn't get called. I've debugged and the catch code path is called instead of the then.</p>