-
Notifications
You must be signed in to change notification settings - Fork 16
/
test.js
74 lines (67 loc) · 1.89 KB
/
test.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import Immutable from 'seamless-immutable';
import createReducer from '../../creators/createReducer';
import onFailure from '.';
const initialState = {
target: 'Some content',
targetLoading: true,
targetError: null
};
const initialPollingState = {
target: 'Some content',
targetLoading: true,
targetError: null,
targetIsRetrying: true,
targetRetryCount: 3,
targetTimeoutID: 3
};
const setUp = {
state: null,
pollingState: null
};
beforeEach(() => {
setUp.state = Immutable(initialState);
setUp.pollingState = Immutable(initialPollingState);
});
describe('onFailure', () => {
it('Sets correctly error and loading', () => {
const reducer = createReducer(setUp.state, {
'@@ACTION/TYPE': onFailure()
});
const newState = reducer(setUp.state, { type: '@@ACTION/TYPE', target: 'target', payload: 'Oops !' });
expect(newState).toEqual({
target: 'Some content',
targetLoading: false,
targetError: 'Oops !'
});
});
it('Sets conditionally error content', () => {
const reducer = createReducer(setUp.state, {
'@@ACTION/TYPE': onFailure(action => `Error: ${action.payload}`)
});
const newState = reducer(setUp.state, { type: '@@ACTION/TYPE', target: 'target', payload: 'Oops !' });
expect(newState).toEqual({
target: 'Some content',
targetLoading: false,
targetError: 'Error: Oops !'
});
});
it('Sets polling target', () => {
const reducer = createReducer(setUp.pollingState, {
'@@ACTION/TYPE_FAILURE': onFailure()
});
const newState = reducer(setUp.pollingState, {
type: '@@ACTION/TYPE_FAILURE',
target: 'target',
payload: 'Boom!',
isPolling: true
});
expect(newState).toEqual({
target: 'Some content',
targetLoading: false,
targetError: 'Boom!',
targetIsRetrying: false,
targetRetryCount: 0,
targetTimeoutID: 3
});
});
});