@@ -8,33 +8,38 @@ describe('ParallelHandler', (): void => {
8
8
beforeEach ( async ( ) : Promise < void > => {
9
9
handlers = [
10
10
{
11
- handleSafe : jest . fn ( ) . mockResolvedValue ( '0' ) ,
11
+ canHandle : jest . fn ( ) ,
12
+ handle : jest . fn ( ) . mockResolvedValue ( '0' ) ,
12
13
} satisfies Partial < AsyncHandler < string , string > > as any ,
13
14
{
14
- handleSafe : jest . fn ( ) . mockResolvedValue ( '1' ) ,
15
+ canHandle : jest . fn ( ) ,
16
+ handle : jest . fn ( ) . mockResolvedValue ( '1' ) ,
15
17
} satisfies Partial < AsyncHandler < string , string > > as any ,
16
18
{
17
- handleSafe : jest . fn ( ) . mockResolvedValue ( '2' ) ,
19
+ canHandle : jest . fn ( ) ,
20
+ handle : jest . fn ( ) . mockResolvedValue ( '2' ) ,
18
21
} satisfies Partial < AsyncHandler < string , string > > as any ,
19
22
] ;
20
23
21
24
parallel = new ParallelHandler ( handlers ) ;
22
25
} ) ;
23
26
24
27
it ( 'can handle all requests.' , async ( ) : Promise < void > => {
25
- handlers [ 0 ] . handleSafe . mockRejectedValueOnce ( new Error ( 'error' ) ) ;
28
+ handlers [ 0 ] . canHandle . mockRejectedValueOnce ( new Error ( 'error' ) ) ;
29
+ handlers [ 1 ] . handle . mockRejectedValueOnce ( new Error ( 'error' ) ) ;
26
30
await expect ( parallel . canHandle ( 'input' ) ) . resolves . toBeUndefined ( ) ;
27
31
} ) ;
28
32
29
33
it ( 'runs all handlers that can handle the input.' , async ( ) : Promise < void > => {
34
+ handlers [ 0 ] . canHandle . mockRejectedValueOnce ( new Error ( 'error' ) ) ;
30
35
await expect ( parallel . handle ( 'abc' ) ) . resolves . toBeUndefined ( ) ;
31
36
32
- expect ( handlers [ 0 ] . handleSafe ) . toHaveBeenCalledTimes ( 1 ) ;
33
- expect ( handlers [ 1 ] . handleSafe ) . toHaveBeenCalledTimes ( 1 ) ;
34
- expect ( handlers [ 2 ] . handleSafe ) . toHaveBeenCalledTimes ( 1 ) ;
37
+ expect ( handlers [ 0 ] . canHandle ) . toHaveBeenLastCalledWith ( 'abc' ) ;
38
+ expect ( handlers [ 1 ] . canHandle ) . toHaveBeenLastCalledWith ( 'abc' ) ;
39
+ expect ( handlers [ 2 ] . canHandle ) . toHaveBeenLastCalledWith ( 'abc' ) ;
35
40
36
- expect ( handlers [ 0 ] . handleSafe ) . toHaveBeenCalledWith ( 'abc' ) ;
37
- expect ( handlers [ 1 ] . handleSafe ) . toHaveBeenCalledWith ( 'abc' ) ;
38
- expect ( handlers [ 2 ] . handleSafe ) . toHaveBeenCalledWith ( 'abc' ) ;
41
+ expect ( handlers [ 0 ] . handle ) . toHaveBeenCalledTimes ( 0 ) ;
42
+ expect ( handlers [ 1 ] . handle ) . toHaveBeenLastCalledWith ( 'abc' ) ;
43
+ expect ( handlers [ 2 ] . handle ) . toHaveBeenLastCalledWith ( 'abc' ) ;
39
44
} ) ;
40
45
} ) ;
0 commit comments