vendredi 31 mai 2019

Jasmine marbles testing NGRX effects

I'm trying to test an NGRX effect using jasmine-marbles but the response I get from effects.myEffect$ appears to have nested operators. What I was expecting was an observable returning a single, flat action. Any help or input would be greatly appreciated.

 it('Test Effect', async(inject([ServicesStub],
    async (servicesStub: ServicesStub) => {

      const payloadRequest = new RequestActionPayload();
      const actionRequest = new RequestAction(payloadRequest);

      const payloadResponse = new ResponseActionPayload();
      const actionResponse = new ResponseActionPayload(payloadResponse);

    const source = hot('a|', { a: actionRequest});

    const effects = new NewEffectService(new Actions(source), ...);

    const expected = cold('-a', { a: actionResponse });
    expect(effects.myEffect$).toBeObservable(expected);}
)));

my effect looks like this:

  @Effect()
  myEffect$ = this.actions$
    .pipe(
      ofType(actions.REQUEST_ACTION),
      map((action: actions.RequestAction) => action.payload),
      switchMap(payload => ... do some work),
      map(([a, b]) => new actions.ResponseAction(new actions.ResponseActionPayload(...)))
    );

my package.json looks like:

"jasmine-marbles": "^0.5.0"
"rxjs": "^6.5.1",
"@ngrx/effects": "^7.4.0",
"@ngrx/router-store": "^7.4.0",
"@ngrx/store": "^7.4.0",
"@ngrx/store-devtools": "^7.4.0",

nested observers/source:

enter image description here

Aucun commentaire:

Enregistrer un commentaire