-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.integ.test.js
55 lines (41 loc) · 1.46 KB
/
index.integ.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
const { createStore, applyMiddleware } = require('redux');
const { enableBatching, batchActions } = require('redux-batched-actions');
const { autoBatchingMiddleware } = require('.');
function newMocks() {
const setA = payload => ({ type: 'SET_A', payload });
const setB = payload => ({ type: 'SET_B', payload });
const reducer = (state = { a: 0, b: 0 }, action) => {
switch (action.type) {
case 'SET_A': return { ...state, a: action.payload };
case 'SET_B': return { ...state, b: action.payload };
default: return state;
}
};
// Handle bundled actions in reducer
const store = createStore(
enableBatching(reducer),
applyMiddleware(autoBatchingMiddleware)
);
return {
store, reducer, setA, setB,
};
}
describe('GIVEN a store with autoBatchingMiddleware and enableBatching', () => {
it('SHOULD call things correctly separately', () => {
const { store, setA, setB } = newMocks();
store.dispatch(setA(1));
store.dispatch(setA(2));
store.dispatch(setB(5));
expect(store.getState()).toEqual({ a: 2, b: 5 });
});
it('SHOULD call things correctly using batchActions', () => {
const { store, setA, setB } = newMocks();
store.dispatch(batchActions([setA(1), setA(2), setB(5)]));
expect(store.getState()).toEqual({ a: 2, b: 5 });
});
it('SHOULD call things correctly using just an array', () => {
const { store, setA, setB } = newMocks();
store.dispatch([setA(1), setA(2), setB(5)]);
expect(store.getState()).toEqual({ a: 2, b: 5 });
});
});