@@ -22,6 +22,7 @@ describe('trace decorator', () => {
2222
2323 describe ( 'Tracing synchronous functions' , ( ) => {
2424 const traceHandlerMock = jest . fn ( ) ;
25+ const traceHandlerMockThrows = jest . fn ( ) ;
2526
2627 class SyncClass {
2728 greetingFrom = [ 'hello from class' ] ;
@@ -35,11 +36,21 @@ describe('trace decorator', () => {
3536 this . greetingFrom . push ( 'hello from method' ) ;
3637 return 'Hello World' ;
3738 }
39+
40+ @trace ( ( ...args ) => {
41+ traceHandlerMockThrows ( ...args ) ;
42+ throw new Error ( 'hello but I throw!' ) ;
43+ } )
44+ helloWorldHandlerThrows ( ) : string {
45+ this . greetingFrom . push ( 'hello from method' ) ;
46+ return 'Hello World' ;
47+ }
3848 }
3949
4050 it ( 'should trace a synchronous function and verify context' , ( ) => {
4151 const instance = new SyncClass ( ) ;
4252 expect ( instance . helloWorld ( ) ) . toBe ( 'Hello World' ) ;
53+ expect ( traceHandlerMock ) . toHaveBeenCalledTimes ( 1 ) ;
4354 expect ( traceHandlerMock ) . toHaveBeenCalledWith (
4455 expect . objectContaining ( {
4556 metadata : expect . objectContaining ( {
@@ -54,6 +65,25 @@ describe('trace decorator', () => {
5465 } )
5566 ) ;
5667 } ) ;
68+
69+ it ( 'should trace a synchronous function and verify helloWorldHandlerThrows' , ( ) => {
70+ const instance = new SyncClass ( ) ;
71+ expect ( ( ) => instance . helloWorldHandlerThrows ( ) ) . toThrowError ( 'hello but I throw!' ) ;
72+ expect ( traceHandlerMockThrows ) . toHaveBeenCalledTimes ( 1 ) ;
73+ expect ( traceHandlerMockThrows ) . toHaveBeenCalledWith (
74+ expect . objectContaining ( {
75+ metadata : expect . objectContaining ( {
76+ class : 'SyncClass' ,
77+ method : 'helloWorldHandlerThrows' ,
78+ name : 'helloWorldHandlerThrows' ,
79+ parameters : [ ] ,
80+ isAsync : false ,
81+ isBound : false
82+ } ) ,
83+ ...successfulExecutionTraceExpectation
84+ } )
85+ ) ;
86+ } ) ;
5787 } ) ;
5888
5989 describe ( 'Asynchronous functions' , ( ) => {
@@ -142,8 +172,8 @@ describe('trace decorator', () => {
142172 url : string ,
143173 traceContext : Record < string , unknown > = { }
144174 ) : Promise < {
145- data : string ;
146- } > {
175+ data : string ;
176+ } > {
147177 return this . fetchDataFunction ( url , traceContext ) ;
148178 }
149179
0 commit comments