-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathsaga.test.js
50 lines (45 loc) · 1.84 KB
/
saga.test.js
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
/**
* Test homeContainer sagas
*/
/* eslint-disable redux-saga/yield-effects */
import { takeLatest, call, put } from 'redux-saga/effects';
import { getRepos } from '@services/repoApi';
import { apiResponseGenerator } from '@utils/testUtils';
import homeContainerSaga, { getGithubRepos } from '../saga';
import { homeContainerTypes } from '../reducer';
describe('HomeContainer saga tests', () => {
const generator = homeContainerSaga();
const repoName = 'mac';
let getGithubReposGenerator = getGithubRepos({ repoName });
it('should start task to watch for REQUEST_GET_GITHUB_REPOS action', () => {
expect(generator.next().value).toEqual(takeLatest(homeContainerTypes.REQUEST_GET_GITHUB_REPOS, getGithubRepos));
});
it('should ensure that the action FAILURE_GET_GITHUB_REPOS is dispatched when the api call fails', () => {
const res = getGithubReposGenerator.next().value;
expect(res).toEqual(call(getRepos, repoName));
const errorResponse = {
errorMessage: 'There was an error while fetching repo informations.'
};
expect(getGithubReposGenerator.next(apiResponseGenerator(false, errorResponse)).value).toEqual(
put({
type: homeContainerTypes.FAILURE_GET_GITHUB_REPOS,
error: errorResponse
})
);
});
it('should ensure that the action SUCCESS_GET_GITHUB_REPOS is dispatched when the api call succeeds', () => {
getGithubReposGenerator = getGithubRepos({ repoName });
const res = getGithubReposGenerator.next().value;
expect(res).toEqual(call(getRepos, repoName));
const reposResponse = {
totalCount: 1,
items: [{ repositoryName: repoName }]
};
expect(getGithubReposGenerator.next(apiResponseGenerator(true, reposResponse)).value).toEqual(
put({
type: homeContainerTypes.SUCCESS_GET_GITHUB_REPOS,
data: reposResponse
})
);
});
});