@@ -17,10 +17,10 @@ interface LambdaInterface {
17
17
type CaptureAsyncFuncMock = jest . SpyInstance < unknown , [ name : string , fcn : ( subsegment ?: Subsegment ) => unknown , parent ?: Segment | Subsegment ] > ;
18
18
const createCaptureAsyncFuncMock = function ( provider : ProviderServiceInterface ) : CaptureAsyncFuncMock {
19
19
return jest . spyOn ( provider , 'captureAsyncFunc' )
20
- . mockImplementation ( ( methodName , callBackFn ) => {
20
+ . mockImplementation ( async ( methodName , callBackFn ) => {
21
21
const subsegment = new Subsegment ( `### ${ methodName } ` ) ;
22
22
jest . spyOn ( subsegment , 'flush' ) . mockImplementation ( ( ) => null ) ;
23
- callBackFn ( subsegment ) ;
23
+ await callBackFn ( subsegment ) ;
24
24
} ) ;
25
25
} ;
26
26
@@ -865,7 +865,6 @@ describe('Class: Tracer', () => {
865
865
const captureAsyncFuncSpy = jest . spyOn ( tracer . provider , 'captureAsyncFunc' ) ;
866
866
class Lambda implements LambdaInterface {
867
867
868
- // TODO: revisit return type & make it more specific
869
868
@tracer . captureMethod ( )
870
869
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
871
870
// @ts -ignore
@@ -895,6 +894,7 @@ describe('Class: Tracer', () => {
895
894
// Prepare
896
895
const tracer : Tracer = new Tracer ( ) ;
897
896
const newSubsegment : Segment | Subsegment | undefined = new Subsegment ( '### dummyMethod' ) ;
897
+ jest . spyOn ( newSubsegment , 'flush' ) . mockImplementation ( ( ) => null ) ;
898
898
jest . spyOn ( tracer . provider , 'getSegment' )
899
899
. mockImplementation ( ( ) => newSubsegment ) ;
900
900
setContextMissingStrategy ( ( ) => null ) ;
@@ -960,17 +960,16 @@ describe('Class: Tracer', () => {
960
960
961
961
}
962
962
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 ) ;
967
965
expect ( captureAsyncFuncSpy ) . toHaveBeenCalledTimes ( 1 ) ;
968
966
expect ( newSubsegment ) . toEqual ( expect . objectContaining ( {
969
967
name : '### dummyMethod' ,
970
968
} ) ) ;
971
969
expect ( 'cause' in newSubsegment ) . toBe ( true ) ;
972
970
expect ( addErrorSpy ) . toHaveBeenCalledTimes ( 1 ) ;
973
971
expect ( addErrorSpy ) . toHaveBeenCalledWith ( new Error ( 'Exception thrown!' ) , false ) ;
972
+ expect . assertions ( 6 ) ;
974
973
975
974
} ) ;
976
975
0 commit comments