@@ -27,8 +27,20 @@ const noop = () => {}
27
27
describe ( 'createActionListenerMiddleware' , ( ) => {
28
28
let store = configureStore ( {
29
29
reducer : ( ) => ( { } ) ,
30
- middleware : [ createActionListenerMiddleware ( ) ] as const ,
30
+ middleware : ( gDM ) => gDM ( ) . prepend ( createActionListenerMiddleware ( ) ) ,
31
31
} )
32
+
33
+ const counterSlice = createSlice ( {
34
+ name : 'counter' ,
35
+ initialState : 0 ,
36
+ reducers : {
37
+ increment ( state ) {
38
+ return state + 1
39
+ } ,
40
+ } ,
41
+ } )
42
+ const { increment } = counterSlice . actions
43
+
32
44
let reducer : jest . Mock
33
45
let middleware : ReturnType < typeof createActionListenerMiddleware >
34
46
@@ -44,7 +56,7 @@ describe('createActionListenerMiddleware', () => {
44
56
reducer = jest . fn ( ( ) => ( { } ) )
45
57
store = configureStore ( {
46
58
reducer,
47
- middleware : [ middleware ] as const ,
59
+ middleware : ( gDM ) => gDM ( ) . prepend ( middleware ) ,
48
60
} )
49
61
} )
50
62
@@ -56,7 +68,7 @@ describe('createActionListenerMiddleware', () => {
56
68
reducer = jest . fn ( ( ) => ( { } ) )
57
69
store = configureStore ( {
58
70
reducer,
59
- middleware : [ middleware ] as const ,
71
+ middleware : ( gDM ) => gDM ( ) . prepend ( middleware ) ,
60
72
} )
61
73
62
74
let foundExtra = null
@@ -78,6 +90,32 @@ describe('createActionListenerMiddleware', () => {
78
90
expect ( resultAction ) . toBe ( originalAction )
79
91
} )
80
92
93
+ test . skip ( 'Allows dispatching a thunk without TS errors' , ( ) => {
94
+ const store = configureStore ( {
95
+ reducer : counterSlice . reducer ,
96
+ middleware : ( gDM ) => gDM ( ) . prepend ( middleware ) ,
97
+ } )
98
+ store . dispatch ( increment ( ) )
99
+
100
+ let testState = 0
101
+
102
+ middleware . addListener (
103
+ ( action , state ) => {
104
+ return increment . match ( action ) && state > 1
105
+ } ,
106
+ ( action , listenerApi ) => {
107
+ // TODO Can't get the thunk dispatch types to carry through
108
+ // listenerApi.dispatch((dispatch, getState) => {
109
+ // testState = getState()
110
+ // })
111
+ }
112
+ )
113
+
114
+ store . dispatch ( increment ( ) )
115
+
116
+ expect ( testState ) . toBe ( 2 )
117
+ } )
118
+
81
119
test ( 'directly subscribing' , ( ) => {
82
120
const listener = jest . fn ( ( _ : TestAction1 ) => { } )
83
121
@@ -132,24 +170,11 @@ describe('createActionListenerMiddleware', () => {
132
170
} )
133
171
134
172
test ( 'Can subscribe with an action predicate function' , ( ) => {
135
- const slice = createSlice ( {
136
- name : 'counter' ,
137
- initialState : 0 ,
138
- reducers : {
139
- increment ( state ) {
140
- return state + 1
141
- } ,
142
- } ,
143
- } )
144
- const { increment } = slice . actions
145
-
146
- store = configureStore ( {
147
- reducer : slice . reducer ,
148
- middleware : [ middleware ] as const ,
173
+ const store = configureStore ( {
174
+ reducer : counterSlice . reducer ,
175
+ middleware : ( gDM ) => gDM ( ) . prepend ( middleware ) ,
149
176
} )
150
177
151
- const listener = jest . fn ( ( _ : TestAction1 ) => { } )
152
-
153
178
let listenerCalls = 0
154
179
155
180
middleware . addListener (
0 commit comments