Skip to content
This repository was archived by the owner on Apr 11, 2019. It is now read-only.

Commit 5abd185

Browse files
committed
Feat: add reducer and action tests
1 parent 6966514 commit 5abd185

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

app/src/containers/FeatureFirstContainer/tests/actions.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import {
77
CLEAR_DATA_ERROR,
88
} from '../constants';
99

10+
// Testing actions is as easy as validating that the actions are dispatch
11+
// The way you think they are being dispatched.
12+
// Just test that your expected Action object is what is actually dispatched.
13+
// If you need help,
14+
// See here: http://redux.js.org/docs/recipes/WritingTests.html
1015
describe('FeatureFirstContainer actions', () => {
1116
it('should dispatch an action to initiate the loading process', () => {
1217
const expectedAction = {

app/src/containers/FeatureFirstContainer/tests/reducer.test.js

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,84 @@ const initialState = {
88
error: {},
99
};
1010

11-
describe('FeatureFirstContainer Reducer', () => {
11+
// testing reducers is really simple.
12+
// pass the reducer initial state, an action and assert the output.
13+
// Easy as cake, but if you need help
14+
// See here: http://redux.js.org/docs/recipes/WritingTests.html
15+
describe('featureComponent reducer', () => {
1216
it('should return the initialState', () => {
1317
expect(
1418
reducer(undefined, {})
1519
).toEqual(initialState);
1620
});
21+
it('should initiate loading', () => {
22+
const stateAfter = {
23+
isLoading: true,
24+
data: {},
25+
error: {},
26+
};
27+
expect(
28+
reducer(initialState, {
29+
type: types.LOAD_DATA_INITIATION,
30+
})
31+
).toEqual(stateAfter);
32+
});
33+
it('should load data successfully', () => {
34+
const data = {
35+
items: ['🤓', '😎', '🤔'],
36+
};
37+
const stateAfter = {
38+
isLoading: false,
39+
data,
40+
error: {},
41+
};
42+
expect(
43+
reducer(
44+
initialState,
45+
{
46+
type: types.LOAD_DATA_SUCCESS,
47+
data,
48+
}
49+
)
50+
).toEqual(stateAfter);
51+
});
52+
it('should fail gracefully when the data doesn\'t load', () => {
53+
const error = {
54+
message: 'An error occured',
55+
};
56+
const stateAfter = {
57+
isLoading: false,
58+
data: {},
59+
error,
60+
};
61+
expect(
62+
reducer(
63+
initialState,
64+
{
65+
type: types.LOAD_DATA_FAILURE,
66+
error,
67+
}
68+
)
69+
).toEqual(stateAfter);
70+
});
71+
it('should clear the errors', () => {
72+
const stateBefore = {
73+
isLoading: false,
74+
error: { message: 'An error has occured' },
75+
data: {},
76+
};
77+
const stateAfter = {
78+
isLoading: false,
79+
error: {},
80+
data: {},
81+
};
82+
expect(
83+
reducer(
84+
stateBefore,
85+
{
86+
type: types.CLEAR_DATA_ERROR,
87+
}
88+
)
89+
).toEqual(stateAfter);
90+
});
1791
});

0 commit comments

Comments
 (0)