@@ -17,10 +17,10 @@ interface LambdaInterface {
1717type CaptureAsyncFuncMock = jest . SpyInstance < unknown , [ name : string , fcn : ( subsegment ?: Subsegment ) => unknown , parent ?: Segment | Subsegment ] > ;
1818const createCaptureAsyncFuncMock = function ( provider : ProviderServiceInterface ) : CaptureAsyncFuncMock {
1919 return jest . spyOn ( provider , 'captureAsyncFunc' )
20- . mockImplementation ( ( methodName , callBackFn ) => {
20+ . mockImplementation ( async ( methodName , callBackFn ) => {
2121 const subsegment = new Subsegment ( `### ${ methodName } ` ) ;
2222 jest . spyOn ( subsegment , 'flush' ) . mockImplementation ( ( ) => null ) ;
23- callBackFn ( subsegment ) ;
23+ await callBackFn ( subsegment ) ;
2424 } ) ;
2525} ;
2626
@@ -865,7 +865,6 @@ describe('Class: Tracer', () => {
865865 const captureAsyncFuncSpy = jest . spyOn ( tracer . provider , 'captureAsyncFunc' ) ;
866866 class Lambda implements LambdaInterface {
867867
868- // TODO: revisit return type & make it more specific
869868 @tracer . captureMethod ( )
870869 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
871870 // @ts -ignore
@@ -895,6 +894,7 @@ describe('Class: Tracer', () => {
895894 // Prepare
896895 const tracer : Tracer = new Tracer ( ) ;
897896 const newSubsegment : Segment | Subsegment | undefined = new Subsegment ( '### dummyMethod' ) ;
897+ jest . spyOn ( newSubsegment , 'flush' ) . mockImplementation ( ( ) => null ) ;
898898 jest . spyOn ( tracer . provider , 'getSegment' )
899899 . mockImplementation ( ( ) => newSubsegment ) ;
900900 setContextMissingStrategy ( ( ) => null ) ;
@@ -960,17 +960,16 @@ describe('Class: Tracer', () => {
960960
961961 }
962962
963- // Act
964- await new Lambda ( ) . handler ( event , context , ( ) => console . log ( 'Lambda invoked!' ) ) ;
965-
966- // Assess
963+ // Act / Assess
964+ await expect ( new Lambda ( ) . handler ( { } , context , ( ) => console . log ( 'Lambda invoked!' ) ) ) . rejects . toThrowError ( Error ) ;
967965 expect ( captureAsyncFuncSpy ) . toHaveBeenCalledTimes ( 1 ) ;
968966 expect ( newSubsegment ) . toEqual ( expect . objectContaining ( {
969967 name : '### dummyMethod' ,
970968 } ) ) ;
971969 expect ( 'cause' in newSubsegment ) . toBe ( true ) ;
972970 expect ( addErrorSpy ) . toHaveBeenCalledTimes ( 1 ) ;
973971 expect ( addErrorSpy ) . toHaveBeenCalledWith ( new Error ( 'Exception thrown!' ) , false ) ;
972+ expect . assertions ( 6 ) ;
974973
975974 } ) ;
976975
0 commit comments