-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtest.js
More file actions
90 lines (89 loc) · 3.35 KB
/
Copy pathtest.js
File metadata and controls
90 lines (89 loc) · 3.35 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import completeTypes from '.';
describe('completeTypes', () => {
it("Completes from an array's element", () => {
const arrTypes = ['AN_ACTION'];
expect(completeTypes({ primaryActions: arrTypes })).toEqual(['AN_ACTION', 'AN_ACTION_SUCCESS', 'AN_ACTION_FAILURE']);
});
it('Completes from an array of multiple elements', () => {
const arrTypes = ['AN_ACTION', 'OTHER_ACTION', 'ANOTHER_ACTION'];
expect(completeTypes({ primaryActions: arrTypes })).toEqual([
'AN_ACTION',
'AN_ACTION_SUCCESS',
'AN_ACTION_FAILURE',
'OTHER_ACTION',
'OTHER_ACTION_SUCCESS',
'OTHER_ACTION_FAILURE',
'ANOTHER_ACTION',
'ANOTHER_ACTION_SUCCESS',
'ANOTHER_ACTION_FAILURE'
]);
});
it('Does not complete from exception cases', () => {
const arrActions = ['AN_ACTION'];
const exceptionCases = ['EXCEPT_ACTION'];
expect(completeTypes({ primaryActions: arrActions, ignoredActions: exceptionCases })).toEqual([
'AN_ACTION',
'AN_ACTION_SUCCESS',
'AN_ACTION_FAILURE',
'EXCEPT_ACTION'
]);
});
it('Custom completers completes all types passed', () => {
const primaryActions = [];
const ignoredActions = [];
const completer = type => [type, `${type}_SUCCESS`, `${type}_FAILURE`];
const customCompleters = [
{ completer, actions: ['CUSTOM_ACTION'] }
];
expect(completeTypes({ primaryActions, ignoredActions, customCompleters })).toEqual([
'CUSTOM_ACTION',
'CUSTOM_ACTION_SUCCESS',
'CUSTOM_ACTION_FAILURE'
]);
});
it('Polling actions completes', () => {
const pollingActions = ['FETCH_1', 'FETCH_2'];
expect(completeTypes({ pollingActions })).toEqual([
'FETCH_1',
'FETCH_1_SUCCESS',
'FETCH_1_FAILURE',
'FETCH_1_RETRY',
'FETCH_1_CANCEL',
'FETCH_2',
'FETCH_2_SUCCESS',
'FETCH_2_FAILURE',
'FETCH_2_RETRY',
'FETCH_2_CANCEL'
]);
});
it('Throws if parameters are not the expected ones', () => {
expect(() => completeTypes({ primaryActions: null })).toThrow(new Error('primaryActions should be an array'));
expect(() => completeTypes({ primaryActions: [null] })).toThrow(new Error('primaryActions should be an array of strings'));
expect(() => completeTypes({ primaryActions: ['ONE'], ignoredActions: null })).toThrow(new Error('ignoredActions should be an array'));
expect(() => completeTypes({ primaryActions: ['ONE'], ignoredActions: [null] })).toThrow(new Error('ignoredActions should be an array of strings'));
expect(() => completeTypes({
primaryActions: ['ONE'],
ignoredActions: ['TWO'],
customCompleters: [{
actions: null
}]
})).toThrow(new Error('actions should be an array'));
expect(() => completeTypes({
primaryActions: ['ONE'],
ignoredActions: ['TWO'],
customCompleters: [{
actions: [null]
}]
})).toThrow(new Error('actions should be an array of strings'));
expect(() => completeTypes({
primaryActions: ['ONE'],
ignoredActions: ['TWO'],
customCompleters: [{
actions: ['THREE'],
completer: null
}]
})).toThrow();
expect(() => completeTypes({ pollingActions: null }).toThrow(new Error('pollingActions should be an array')));
expect(() => completeTypes({ pollingActions: [null] }).toThrow(new Error('pollingActions should be an array of strings')));
});
});