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

Commit b4dcbe5

Browse files
authoredAug 23, 2016
Merge pull request #21 from RyanCCollins/fix_rc_fix_testing
Fix rc fix testing
2 parents 8c99fc0 + 5abd185 commit b4dcbe5

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import expect from 'expect';
2+
import * as actions from '../actions';
3+
import {
4+
LOAD_DATA_INITIATION,
5+
LOAD_DATA_SUCCESS,
6+
LOAD_DATA_FAILURE,
7+
CLEAR_DATA_ERROR,
8+
} from '../constants';
9+
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
15+
describe('FeatureFirstContainer actions', () => {
16+
it('should dispatch an action to initiate the loading process', () => {
17+
const expectedAction = {
18+
type: LOAD_DATA_INITIATION,
19+
};
20+
expect(
21+
actions.loadDataInitiation()
22+
).toEqual(expectedAction);
23+
});
24+
it('should dispatch an action to successfully finish loading', () => {
25+
const data = {
26+
items: [],
27+
};
28+
const expectedAction = {
29+
type: LOAD_DATA_SUCCESS,
30+
data,
31+
};
32+
expect(
33+
actions.loadDataSuccess(data)
34+
).toEqual(expectedAction);
35+
});
36+
it('should dispatch an action with an error describing a failure to load data', () => {
37+
const error = {
38+
message: 'An error occured',
39+
};
40+
const expectedAction = {
41+
type: LOAD_DATA_FAILURE,
42+
error,
43+
};
44+
expect(
45+
actions.loadDataFailure(error)
46+
).toEqual(expectedAction);
47+
});
48+
it('should dispatch an action to clear the error', () => {
49+
const expectedAction = {
50+
type: CLEAR_DATA_ERROR,
51+
};
52+
expect(
53+
actions.clearDataError()
54+
).toEqual(expectedAction);
55+
});
56+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import * as types from '../constants';
2+
import reducer from '../reducer';
3+
import expect from 'expect';
4+
5+
const initialState = {
6+
isLoading: false,
7+
data: {},
8+
error: {},
9+
};
10+
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', () => {
16+
it('should return the initialState', () => {
17+
expect(
18+
reducer(undefined, {})
19+
).toEqual(initialState);
20+
});
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+
});
91+
});

0 commit comments

Comments
 (0)
This repository has been archived.