jeudi 11 avril 2019

How to tell Jasmine Marbles to return an array as a single unit and not as two separate calls to observers

A Jasmine Marbles test I'm writing is calling an Observable once for each element in an array when I want it to call the Observable once and pass the entire array.

This is the test code;

it('sends an action when fetching the conversion list', () => {
  const service_response = [CONVERSION_1, CONVERSION_2];
  const action = new ConversionActions.ConversionFetchList({ timestamp: 0 });
  const outcome = new ConversionActions.ConversionUpdatesReceived({ items: service_response });

  actions = hot('-(a|)', { a: action });
  const response = cold('-a|', { a: service_response });
  conversion_service.get_conversions.and.returnValue(service_response);

  const expected = cold('--b', { b: outcome });
  expect(effects.conversion_fetch_list$)
    .toBeObservable(expected);
});

In debugging I see the observable getting called twice: one for CONVERSION_1 and another time for CONVERSION_2. But what it needs to do is call the observer once with the array of conversions.

Aucun commentaire:

Enregistrer un commentaire