File size: 1,786 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
/**
* Tests for HomePage sagas
*/
import { put, takeLatest } from 'redux-saga/effects';
import { LOAD_REPOS } from 'containers/App/constants';
import { reposLoaded, repoLoadingError } from 'containers/App/actions';
import githubData, { getRepos } from '../saga';
const username = 'mxstbr';
/* eslint-disable redux-saga/yield-effects */
describe('getRepos Saga', () => {
let getReposGenerator;
// We have to test twice, once for a successful load and once for an unsuccessful one
// so we do all the stuff that happens beforehand automatically in the beforeEach
beforeEach(() => {
getReposGenerator = getRepos();
const selectDescriptor = getReposGenerator.next().value;
expect(selectDescriptor).toMatchSnapshot();
const callDescriptor = getReposGenerator.next(username).value;
expect(callDescriptor).toMatchSnapshot();
});
it('should dispatch the reposLoaded action if it requests the data successfully', () => {
const response = [
{
name: 'First repo',
},
{
name: 'Second repo',
},
];
const putDescriptor = getReposGenerator.next(response).value;
expect(putDescriptor).toEqual(put(reposLoaded(response, username)));
});
it('should call the repoLoadingError action if the response errors', () => {
const response = new Error('Some error');
const putDescriptor = getReposGenerator.throw(response).value;
expect(putDescriptor).toEqual(put(repoLoadingError(response)));
});
});
describe('githubDataSaga Saga', () => {
const githubDataSaga = githubData();
it('should start task to watch for LOAD_REPOS action', () => {
const takeLatestDescriptor = githubDataSaga.next().value;
expect(takeLatestDescriptor).toEqual(takeLatest(LOAD_REPOS, getRepos));
});
});
|