forked from flow-typed/flow-typed
/
test_toolkit_v1.x.x.js
148 lines (128 loc) · 3.34 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// @flow
import { describe, it, test } from 'flow-typed-test';
import {
createAction,
createReducer,
configureStore,
type Middleware,
type Store,
type Action,
} 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,
});
const store: Store<{
test: { ... },
test2: number,
...
}, Action<{ ... }>> = configureStore({
reducer: {
test: (a) => ({}),
test2: (a) => 2,
},
});
const failedStore: Store<{|
test: { ... },
test2: number,
// $FlowExpectedError[prop-missing] foo is missing
|}, Action<{ ... }>> = configureStore({
reducer: {
test: (a) => ({}),
test2: (a) => 2,
foo: () => 'bar',
},
});
// const failedStore2: Store<{
// test: { ... },
// // Expect this to fail but currently does not
// test2: string,
// ...
// }, Action<{ ... }>> = configureStore({
// reducer: {
// test: (a) => ({}),
// test2: (a) => 2,
// },
// });
});
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();
})
});
});