File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
packages/toolkit/src/tests Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,34 @@ const anyAction = { type: 'foo' } as AnyAction
147
147
} )
148
148
} ) ( )
149
149
150
+ /**
151
+ * Should handle reject withvalue within a try catch block
152
+ *
153
+ * Note:
154
+ * this is a sample code taken from #1605
155
+ *
156
+ */
157
+ ; ( async ( ) => {
158
+ type ResultType = {
159
+ text : string
160
+ }
161
+ const demoPromise = async ( ) : Promise < ResultType > =>
162
+ new Promise ( ( resolve , _ ) => resolve ( { text : '' } ) )
163
+ const thunk = createAsyncThunk ( 'thunk' , async ( args , thunkAPI ) => {
164
+ try {
165
+ const result = await demoPromise ( )
166
+ return result
167
+ } catch ( error ) {
168
+ return thunkAPI . rejectWithValue ( error )
169
+ }
170
+ } )
171
+ createReducer ( { } , ( builder ) =>
172
+ builder . addCase ( thunk . fulfilled , ( s , action ) => {
173
+ expectType < ResultType > ( action . payload )
174
+ } )
175
+ )
176
+ } ) ( )
177
+
150
178
{
151
179
interface Item {
152
180
name : string
You can’t perform that action at this time.
0 commit comments