/ common / features / rates / sagas.spec.ts
sagas.spec.ts
 1  import { call, put } from 'redux-saga/effects';
 2  
 3  import { fetchRates } from 'api/rates';
 4  import * as actions from './actions';
 5  import * as sagas from './sagas';
 6  
 7  describe('fetch rates saga success', () => {
 8    const saga = sagas.fetchRatesSaga(actions.fetchCCRatesRequested());
 9    it('should fetch the rates', () => {
10      expect(saga.next().value).toEqual(call(fetchRates, []));
11    });
12    it('should dispatch a success action', () => {
13      expect(saga.next({}).value).toEqual(put(actions.fetchCCRatesSucceeded({})));
14    });
15    it('should be done', () => {
16      expect(saga.next().done).toEqual(true);
17    });
18  });
19  
20  describe('fetch rates saga failure', () => {
21    const saga = sagas.fetchRatesSaga(actions.fetchCCRatesRequested());
22    it('it should throw and dispatch a failure action', () => {
23      saga.next();
24      expect(saga.throw!().value).toEqual(put(actions.fetchCCRatesFailed()));
25    });
26    it('should be done', () => {
27      expect(saga.next().done).toEqual(true);
28    });
29  });