-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.unit.test.js
53 lines (41 loc) · 1.47 KB
/
index.unit.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
jest.mock('redux-batched-actions', () => ({
batchActions: jest.fn(x => x),
}));
const reduxAutoBatchedActions = require('./index');
const { autoBatchingMiddleware } = reduxAutoBatchedActions;
const reduxBatchedActions = require('redux-batched-actions');
const { batchActions } = reduxBatchedActions;
function newMocks() {
const next = jest.fn();
const process = autoBatchingMiddleware()(next);
return { next, process };
}
describe('GIVEN a store with autoBatchingMiddleware', () => {
describe('WHEN a non-array action is passed', () => {
const { next, process } = newMocks();
const action = { type: 'testAction' };
process(action);
it('THEN next is called with the given action', () => {
expect(next).toHaveBeenCalledTimes(1);
expect(next).toHaveBeenCalledWith(action);
});
});
describe('WHEN an array action is passed', () => {
const { next, process } = newMocks();
const action = [
{ type: 'testAction1' },
{ type: 'testAction2' },
function testActionFunc() {},
];
process(action);
it('THEN batchActions is called with said array and the result passed to next', () => {
expect(next).toHaveBeenCalledTimes(1);
expect(batchActions).toHaveBeenCalledTimes(1);
expect(batchActions.mock.calls[0][0]).toBe(action);
expect(batchActions.mock.calls[0][0]).toBe(next.mock.calls[0][0]);
});
it('THEN concatenate all actions names', () => {
expect(batchActions.mock.calls[0][1]).toBe('testAction1, testAction2, testActionFunc');
});
});
});