Within our angular web application, we have implemented NgRx-effects that rely on various data sources within our store. To achieve this, we have adopted the suggested withLatestFrom
strategy:
withLatestFrom(
this.store.pipe(select(...)),
this.store.pipe(select(...)),
...
)
While this method works effectively in production, it poses challenges when it comes to unit testing the effects.
Currently, our unit tests involve jasmine-marbles, jasmine spy-objects, and the ngrx MockStore (NgRx 7+). The main difficulty lies in providing the necessary store state to ensure that the selectors function correctly.
For instance, in our EXAMPLE-EFFECT, as illustrated below:
@Effect()
getStammdatenDetails$: Observable<Action> = this.actions$.pipe(
ofType(StammdatenItemDetailActionTypes.REQUEST_DETAILS),
withLatestFrom(
this.store.pipe(select(fromRoot.getMetadata)),
this.store.pipe(select(fromRoot.getCustomerId)),
this.store.pipe(select(fromRoot.getRouterParams))
),
mergeMap(([action, metadata, customerId, params]) => {
*effect logic*
})
);
We are seeking further guidance or helpful resources that could assist us in effectively unit testing such effects. Any insights on streamlining the testing process or refining the effects for better testability would be greatly appreciated.