@@ -8,33 +8,38 @@ describe('ParallelHandler', (): void => {
88 beforeEach ( async ( ) : Promise < void > => {
99 handlers = [
1010 {
11- handleSafe : jest . fn ( ) . mockResolvedValue ( '0' ) ,
11+ canHandle : jest . fn ( ) ,
12+ handle : jest . fn ( ) . mockResolvedValue ( '0' ) ,
1213 } satisfies Partial < AsyncHandler < string , string > > as any ,
1314 {
14- handleSafe : jest . fn ( ) . mockResolvedValue ( '1' ) ,
15+ canHandle : jest . fn ( ) ,
16+ handle : jest . fn ( ) . mockResolvedValue ( '1' ) ,
1517 } satisfies Partial < AsyncHandler < string , string > > as any ,
1618 {
17- handleSafe : jest . fn ( ) . mockResolvedValue ( '2' ) ,
19+ canHandle : jest . fn ( ) ,
20+ handle : jest . fn ( ) . mockResolvedValue ( '2' ) ,
1821 } satisfies Partial < AsyncHandler < string , string > > as any ,
1922 ] ;
2023
2124 parallel = new ParallelHandler ( handlers ) ;
2225 } ) ;
2326
2427 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' ) ) ;
2630 await expect ( parallel . canHandle ( 'input' ) ) . resolves . toBeUndefined ( ) ;
2731 } ) ;
2832
2933 it ( 'runs all handlers that can handle the input.' , async ( ) : Promise < void > => {
34+ handlers [ 0 ] . canHandle . mockRejectedValueOnce ( new Error ( 'error' ) ) ;
3035 await expect ( parallel . handle ( 'abc' ) ) . resolves . toBeUndefined ( ) ;
3136
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' ) ;
3540
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' ) ;
3944 } ) ;
4045} ) ;
0 commit comments