forked from flow-typed/flow-typed
/
test_toolkit_v1.x.x.js
111 lines (94 loc) · 2.48 KB
/
test_toolkit_v1.x.x.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// @flow
import { describe, it, test } from 'flow-typed-test';
import {
createAction,
createReducer,
configureStore,
type Middleware,
} from '@reduxjs/toolkit';
describe('@redux/toolkit', () => {
describe('createAction', () => {
it('supports being called with an action type string', () => {
createAction('increment');
});
it('supports being called with an action type string and a payload type', () => {
type Payload = $ReadOnly<{|
someData: 'The FitnessGram Pacer Test is a multistage aerobic capacity test that progressively gets...',
|}>;
createAction<Payload>('injectData');
});
});
describe('createReducer', () => {
it('supports being called with an object map', () => {
const state = {
name: 'Pelle',
};
const SET_NAME = 'SET_NAME';
createReducer(state, {
[SET_NAME]: (state, action) => {
state.name = action.payload.name;
}
});
});
it('supports being called with an builder callback', () => {
const state = {
name: 'Pelle',
};
const setName = createAction<string>('SET_NAME');
createReducer(state, builder => {
builder.addCase(setName, (state, action) => {
state.name = action.payload.name;
});
});
});
});
describe('createStore', () => {
const reducer = createReducer({}, {
'a': (state, action) => {
state.name = action.payload.name;
},
});
test('with basic reducer', () => {
configureStore({
reducer,
});
});
test('full example', () => {
const preloadedState = {
todos: [
{
text: 'Eat food',
completed: true,
},
{
text: 'Exercise',
completed: false,
},
],
visibilityFilter: 'SHOW_COMPLETED',
};
const reduxBatch: any = {};
configureStore({
reducer,
devTools: process.env.NODE_ENV !== 'production',
preloadedState,
enhancers: [reduxBatch],
})
});
test('middleware', () => {
declare var logger: Middleware<any, any>;
configureStore({
reducer,
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(logger),
})
configureStore({
reducer,
middleware: [logger],
})
});
test('errors', () => {
// $FlowExpectedError[incompatible-call]
configureStore();
})
});
});