@@ -2,10 +2,14 @@ import { FinalizeHandlerArguments, HandlerExecutionContext, MiddlewareStack, Ret
2
2
3
3
import { getRetryPlugin , retryMiddleware , retryMiddlewareOptions } from "./retryMiddleware" ;
4
4
5
- describe ( " getRetryPlugin" , ( ) => {
5
+ describe ( getRetryPlugin . name , ( ) => {
6
6
const mockClientStack = {
7
7
add : jest . fn ( ) ,
8
8
} ;
9
+ const mockRetryStrategy = {
10
+ mode : "mock" ,
11
+ retry : jest . fn ( ) ,
12
+ } ;
9
13
10
14
afterEach ( ( ) => {
11
15
jest . clearAllMocks ( ) ;
@@ -16,7 +20,7 @@ describe("getRetryPlugin", () => {
16
20
it ( `when maxAttempts=${ maxAttempts } ` , ( ) => {
17
21
getRetryPlugin ( {
18
22
maxAttempts : ( ) => Promise . resolve ( maxAttempts ) ,
19
- retryStrategy : { } as RetryStrategy ,
23
+ retryStrategy : jest . fn ( ) . mockResolvedValue ( mockRetryStrategy ) ,
20
24
} ) . applyToStack ( ( mockClientStack as unknown ) as MiddlewareStack < any , any > ) ;
21
25
expect ( mockClientStack . add ) . toHaveBeenCalledTimes ( 1 ) ;
22
26
expect ( mockClientStack . add . mock . calls [ 0 ] [ 1 ] ) . toEqual ( retryMiddlewareOptions ) ;
@@ -25,7 +29,11 @@ describe("getRetryPlugin", () => {
25
29
} ) ;
26
30
} ) ;
27
31
28
- describe ( "retryMiddleware" , ( ) => {
32
+ describe ( retryMiddleware . name , ( ) => {
33
+ const mockRetryStrategy = {
34
+ mode : "mock" ,
35
+ retry : jest . fn ( ) ,
36
+ } ;
29
37
afterEach ( ( ) => {
30
38
jest . clearAllMocks ( ) ;
31
39
} ) ;
@@ -36,22 +44,17 @@ describe("retryMiddleware", () => {
36
44
const args = {
37
45
request : { } ,
38
46
} ;
39
- const mockRetryStrategy = {
40
- mode : "mock" ,
41
- maxAttempts,
42
- retry : jest . fn ( ) ,
43
- } ;
44
47
const context : HandlerExecutionContext = { } ;
45
48
46
49
await retryMiddleware ( {
47
50
maxAttempts : ( ) => Promise . resolve ( maxAttempts ) ,
48
- retryStrategy : mockRetryStrategy ,
51
+ retryStrategy : jest . fn ( ) . mockResolvedValue ( { ... mockRetryStrategy , maxAttempts } ) ,
49
52
} ) (
50
53
next ,
51
54
context
52
55
) ( args as FinalizeHandlerArguments < any > ) ;
53
56
expect ( mockRetryStrategy . retry ) . toHaveBeenCalledTimes ( 1 ) ;
54
57
expect ( mockRetryStrategy . retry ) . toHaveBeenCalledWith ( next , args ) ;
55
- expect ( context . userAgent ) . toContainEqual ( [ "cfg/retry-mode" , "mock" ] ) ;
58
+ expect ( context . userAgent ) . toContainEqual ( [ "cfg/retry-mode" , mockRetryStrategy . mode ] ) ;
56
59
} ) ;
57
60
} ) ;
0 commit comments