Reputation: 1130
We have an Angular project are using the NGRX store. That store has some effectsThe are basically all working the same way: trigger action -> API call -> success action. The API calls are all done, using auto generated API Clients (they are all generated the same way based on Open API spec files). All API methods return Observables with the result.
Now we are using jasmine-marbles to test them. All tests do have the same pattern and all succeed except of one. The one request shall test a file download.
it('loads a something file', () => {
const action = SomethingActions.Get({ param: 's1' });
actions$ = hot('--a-', { a: action });
const api = cold('--b', { b: new Blob([TEST_DATA]) });
const expected = cold('----c', {
c: SomethingActions.GetSuccess({ param: 's1', records: EXPECTED_RESULT }),
});
when(fileServiceMock.getFile('something-s1.txt')).thenReturn(api);
// effects.loadSomething$.subscribe((result) => {
// console.log(result);
// });
expect(effects.loadSomething$).toBeObservable(expected);
verify(fileServiceMock.getFile('something-s1.txt')).once();
});
The commented out part will log the expected result, but only after the test case results in an error:
Expect $.length = 0 to equal 1.
The code of the effect looks like this:
public loadSomething$ = createEffect(() =>
this.actions$.pipe(
ofType(SomethingActions.Get),
mergeMap(({ param }) => {
return fileService.getFile(`something-${param}.txt`)).pipe(
mergeMap(async (blob) => await blob.text()),
catchError(() => of(DEFAULT_DATA)),
map((csv) => SomethingActions.GetSuccess({ spindle, records: parseData(csv) }))
);
}),
));
Does anybody have any idea, why this test case is not working?
Edit: Using tap(x => console.log(x))
in various places inside the effect always shows, that the effect returns the expected result during the test.
Upvotes: 0
Views: 244