@@ -17,12 +17,13 @@ describe('createAsyncThunk', () => {
17
17
18
18
const result = 42
19
19
const args = 123
20
- const requestId = '1 '
20
+ let generatedRequestId = ''
21
21
22
22
const thunkActionCreator = createAsyncThunk (
23
23
'testType' ,
24
- async ( args : number ) => {
24
+ async ( args : number , { requestId } ) => {
25
25
passedArgs = args
26
+ generatedRequestId = requestId
26
27
return result
27
28
}
28
29
)
@@ -35,31 +36,32 @@ describe('createAsyncThunk', () => {
35
36
36
37
expect ( dispatch ) . toHaveBeenNthCalledWith (
37
38
1 ,
38
- thunkActionCreator . pending ( args , requestId )
39
+ thunkActionCreator . pending ( args , generatedRequestId )
39
40
)
40
41
41
42
expect ( dispatch ) . toHaveBeenNthCalledWith (
42
43
2 ,
43
- thunkActionCreator . fulfilled ( result , args , requestId )
44
+ thunkActionCreator . fulfilled ( result , args , generatedRequestId )
44
45
)
45
46
46
47
expect ( dispatch ) . toHaveBeenNthCalledWith (
47
48
3 ,
48
- thunkActionCreator . finished ( args , requestId )
49
+ thunkActionCreator . finished ( args , generatedRequestId )
49
50
)
50
51
} )
51
52
52
53
it ( 'accepts arguments and dispatches the actions on reject' , async ( ) => {
53
54
const dispatch = jest . fn ( )
54
55
55
56
const args = 123
56
- const requestId = '1 '
57
+ let generatedRequestId = ''
57
58
58
59
const error = new Error ( 'Panic!' )
59
60
60
61
const thunkActionCreator = createAsyncThunk (
61
62
'testType' ,
62
- async ( args : number ) => {
63
+ async ( args : number , { requestId } ) => {
64
+ generatedRequestId = requestId
63
65
throw error
64
66
}
65
67
)
@@ -70,17 +72,17 @@ describe('createAsyncThunk', () => {
70
72
71
73
expect ( dispatch ) . toHaveBeenNthCalledWith (
72
74
1 ,
73
- thunkActionCreator . pending ( args , requestId )
75
+ thunkActionCreator . pending ( args , generatedRequestId )
74
76
)
75
77
76
78
expect ( dispatch ) . toHaveBeenNthCalledWith (
77
79
2 ,
78
- thunkActionCreator . rejected ( error , args , requestId )
80
+ thunkActionCreator . rejected ( error , args , generatedRequestId )
79
81
)
80
82
81
83
expect ( dispatch ) . toHaveBeenNthCalledWith (
82
84
3 ,
83
- thunkActionCreator . finished ( args , requestId )
85
+ thunkActionCreator . finished ( args , generatedRequestId )
84
86
)
85
87
} )
86
88
} )
0 commit comments