title: Unit testing NgRx effect to ensure the service method was called - ain't working
body: <p>I am using NgRx ^7.0.0 version.
  This is my NgRx effect class:</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import { ApisService } from '../apis.service';
  import { Effect, Actions, ofType } from '@ngrx/effects';
  import { Observable } from 'rxjs';
  import { ApisActionTypes, ApisFetched } from './apis.actions';
  import { mergeMap, map } from 'rxjs/operators';
  
  @Injectable()
  export class ApisEffects {
  
    constructor(private apisS: ApisService, private actions$: Actions) { }
  
    @Effect()
    $fetchApisPaths: Observable&lt;any&gt; = this.actions$.pipe(
      ofType(ApisActionTypes.FetchApisPaths),
      mergeMap(() =&gt;
        this.apisS.fetchHardCodedAPIPaths().pipe(
          map(res =&gt; new ApisFetched(res))
        )
      )
    );
  }
  </code></pre>
  
  <p>And that's a simple test. As you can see it should fail, but is always passing.
  I followed similar question here on StackOverflow <a href="https://stackoverflow.com/questions/48318095/how-to-unit-test-this-effect-with-dispatch-false">How to unit test this effect (with {dispatch: false})?</a> but it doesn't work for me, as if the code execution never enters the effects.$fetchApisPaths.subscribe block</p>
  
  <pre><code>import { TestBed } from '@angular/core/testing';
  import { provideMockActions } from '@ngrx/effects/testing';
  import { hot, cold } from 'jasmine-marbles';
  import { Observable, ReplaySubject } from 'rxjs';
  import { ApisEffects } from '../state/apis.effects';
  import { ApisFetch, ApisFetched } from '../state/apis.actions';
  import { IApiPath } from '../models';
  import { convertPaths, getAPIPathsAsJson, ApisService } from '../apis.service';
  import { ApisServiceMock } from './mocks';
  
  describe('Apis Effects', () =&gt; {
    let effects: ApisEffects;
    let actions: Observable&lt;any&gt;;
    let apisS: ApisService;
  
    beforeEach(() =&gt; {
      TestBed.configureTestingModule({
        providers: [
          ApisEffects,
          provideMockActions(() =&gt; actions),
          {
            provide: ApisService,
            useClass: ApisServiceMock
          }
        ]
      });
  
      effects = TestBed.get(ApisEffects);
      apisS = TestBed.get(ApisService);
    });
  
    it('should call ApisService method() to get Api Paths', () =&gt; {
      const spy = spyOn(apisS, 'fetchHardCodedAPIPaths');
  
      const action = new ApisFetch();
      actions = hot('--a-', {a: action});
  
      effects.$fetchApisPaths.subscribe(() =&gt; {
        console.log('%c effect trigerred', 'color: orange; border: 1px solid red;');
        // expect(spy).toHaveBeenCalled();
        expect(true).toBe(false); // never fails
      });
    });
  });
  </code></pre>
  
  <p>Just in case I am doing smthg stupid with actions, here is the actions file:
  Most likely I am not, since it's working in the app as expected.</p>
  
  <pre><code>import { Action } from '@ngrx/store';
  import { IApiPath } from '../models';
  
  export enum ApisActionTypes {
      FetchApisPaths = '[Apis] Fetch Paths',
      FetchedApisPaths = '[Apis] Fetched Paths'
  }
  
  export class ApisFetch implements Action {
      readonly type = ApisActionTypes.FetchApisPaths;
  }
  
  export class ApisFetched implements Action {
      readonly type = ApisActionTypes.FetchedApisPaths;
      constructor(public payload: IApiPath[]) {}
  }
  
  export type ApisActions = ApisFetch | ApisFetched;
  </code></pre>
  
  <p>=======================EDIT==============================</p>
  
  <p>I have used an example from official ngrx docs <a href="https://ngrx.io/guide/effects/testing" rel="noreferrer">https://ngrx.io/guide/effects/testing</a> and now I can successfully enter the subscribe block below, I get both console logs logged, but the test succeeds. This is bizarre! I have tried throwing errors from the subscribe block and the test still succeeds.</p>
  
  <pre><code>it('should work also', () =&gt; {
      actions$ = new ReplaySubject(1);
  
      actions$.next(new ApisFetch());
  
      effects.$fetchApisPaths.subscribe(result =&gt; {
        console.log('will be logged');
        expect(true).toBe(false); // should fail but nothing happens - test succeeds
        console.log(' --------- after '); // doesn't get called, so the code
        // execution stops on expect above
      });
    });
  </code></pre>