Skip to content

Commit 8335af8

Browse files
committed
Add test for RequestingReducer
1 parent d992a5e commit 8335af8

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import RequestingReducer from './RequestingReducer';
2+
3+
describe('RequestingReducer', () => {
4+
const requestActionType = 'SomeAction.REQUEST_SOMETHING';
5+
const requestActionTypeFinished = 'SomeAction.REQUEST_SOMETHING_FINISHED';
6+
7+
it('returns default state with invalid action type', () => {
8+
const action = { type: '' };
9+
10+
expect(RequestingReducer.reducer(undefined, action)).toEqual(RequestingReducer.initialState);
11+
});
12+
13+
describe('handle REQUEST_* action types', () => {
14+
it('should add the request action type as a key on the state and assign the value as true', () => {
15+
const action = { type: requestActionType };
16+
17+
const actualResult = RequestingReducer.reducer(RequestingReducer.initialState, action);
18+
const expectedResult = {
19+
[requestActionType]: true,
20+
};
21+
22+
expect(actualResult).toEqual(expectedResult);
23+
});
24+
});
25+
26+
describe('handle REQUEST_*_FINISHED action types', () => {
27+
it('should update the request action type key on the state and assign the value to false', () => {
28+
const action = { type: requestActionTypeFinished };
29+
30+
const actualResult = RequestingReducer.reducer(RequestingReducer.initialState, action);
31+
const expectedResult = {
32+
[requestActionType]: false,
33+
};
34+
35+
expect(actualResult).toEqual(expectedResult);
36+
});
37+
});
38+
});

0 commit comments

Comments
 (0)