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

Commit 6966514

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

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
describe('FeatureFirstContainer actions', () => {
11+
it('should dispatch an action to initiate the loading process', () => {
12+
const expectedAction = {
13+
type: LOAD_DATA_INITIATION,
14+
};
15+
expect(
16+
actions.loadDataInitiation()
17+
).toEqual(expectedAction);
18+
});
19+
it('should dispatch an action to successfully finish loading', () => {
20+
const data = {
21+
items: [],
22+
};
23+
const expectedAction = {
24+
type: LOAD_DATA_SUCCESS,
25+
data,
26+
};
27+
expect(
28+
actions.loadDataSuccess(data)
29+
).toEqual(expectedAction);
30+
});
31+
it('should dispatch an action with an error describing a failure to load data', () => {
32+
const error = {
33+
message: 'An error occured',
34+
};
35+
const expectedAction = {
36+
type: LOAD_DATA_FAILURE,
37+
error,
38+
};
39+
expect(
40+
actions.loadDataFailure(error)
41+
).toEqual(expectedAction);
42+
});
43+
it('should dispatch an action to clear the error', () => {
44+
const expectedAction = {
45+
type: CLEAR_DATA_ERROR,
46+
};
47+
expect(
48+
actions.clearDataError()
49+
).toEqual(expectedAction);
50+
});
51+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
describe('FeatureFirstContainer Reducer', () => {
12+
it('should return the initialState', () => {
13+
expect(
14+
reducer(undefined, {})
15+
).toEqual(initialState);
16+
});
17+
});

0 commit comments

Comments
 (0)