-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreducer.test.js
More file actions
54 lines (48 loc) · 1.74 KB
/
reducer.test.js
File metadata and controls
54 lines (48 loc) · 1.74 KB
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
import { homeContainerReducer, initialState, homeContainerTypes } from '../reducer';
/* eslint-disable default-case, no-param-reassign */
describe('HomContainer reducer tests', () => {
let state;
beforeEach(() => {
state = initialState;
});
it('should return the initial state', () => {
expect(homeContainerReducer(undefined, {})).toEqual(state);
});
it('should return the initial state when an action of type FETCH_USER is dispatched', () => {
const repoName = 'Mohammed Ali Chherawalla';
const expectedResult = { ...state, repoName };
expect(
homeContainerReducer(state, {
type: homeContainerTypes.REQUEST_GET_GITHUB_REPOS,
repoName
})
).toEqual(expectedResult);
});
it('should ensure that the user data is present and userLoading = false when FETCH_USER_SUCCESS is dispatched', () => {
const data = { name: 'Mohammed Ali Chherawalla' };
const expectedResult = { ...state, reposData: data };
expect(
homeContainerReducer(state, {
type: homeContainerTypes.SUCCESS_GET_GITHUB_REPOS,
data
})
).toEqual(expectedResult);
});
it('should ensure that the userErrorMessage has some data and userLoading = false when FETCH_USER_FAILURE is dispatched', () => {
const error = 'something_went_wrong';
const expectedResult = { ...state, reposError: error };
expect(
homeContainerReducer(state, {
type: homeContainerTypes.FAILURE_GET_GITHUB_REPOS,
error
})
).toEqual(expectedResult);
});
it('should return the initial state when CLEAR_GITHUB_REPOS is dispatched', () => {
expect(
homeContainerReducer(state, {
type: homeContainerTypes.CLEAR_GITHUB_REPOS
})
).toEqual(initialState);
});
});