title: How to check whether service method was called from within subscribe()
body: <p>I've got a reactive form and during submission I send a http request to an API and based on its' results (success / failure) I'm calling my alert service to display an alert:</p>
  
  <pre><code>public submit(formValues): void {
      this.generationProjectService
          .add(
              new CreateGenerationProjectRequest(
                  formValues.selectedIndustry,
                  formValues.selectedEdition,
                  formValues.selectedDate,
                  formValues.selectedTemplate,
                  formValues.selectedImportant
              )
          )
          .subscribe(
              newGenerationProject =&gt; {
                  this.domainEventService.onNewGenerationProject.emit(newGenerationProject);
  
                  this.alertService.success('Project was successfully added to Overnight Generation');
              },
              () =&gt; {
                  this.alertService.error('Something went wrong');
              }
          );
      this.close();
  }
  </code></pre>
  
  <p>This works great and I would like to test these however I'm struggling to understand to.</p>
  
  <pre><code>fit('should notify failed project addition', () =&gt; {
      spyOn(generationProjectService, 'add').and.throwError('up');
      const errorSpy = spyOn(alertService, 'error').and.callThrough();
  
      component.submit({});
  
      fixture.detectChanges();
  
      fixture.whenStable().then(() =&gt; {
          expect(errorSpy).toHaveBeenCalledTimes(1);
      });
  });
  </code></pre>
  
  <p>But this does not work.</p>
  
  <p>What do I have to change in my test case in order to have this working. Or perhaps I can make changes to my code in order to make this more testable?</p>