@@ -1042,6 +1042,30 @@ describe('BaseClient', () => {
10421042 expect ( TestClient . instance ! . event ! . transaction ) . toBe ( '/adopt/dont/shop' ) ;
10431043 } ) ;
10441044
1045+ test ( 'calls `beforeSendTransaction` and drops spans' , ( ) => {
1046+ const beforeSendTransaction = jest . fn ( event => {
1047+ event . spans = [ { span_id : 'span5' , trace_id : 'trace1' , start_timestamp : 1234 } ] ;
1048+ return event ;
1049+ } ) ;
1050+ const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , beforeSendTransaction } ) ;
1051+ const client = new TestClient ( options ) ;
1052+
1053+ client . captureEvent ( {
1054+ transaction : '/dogs/are/great' ,
1055+ type : 'transaction' ,
1056+ spans : [
1057+ { span_id : 'span1' , trace_id : 'trace1' , start_timestamp : 1234 } ,
1058+ { span_id : 'span2' , trace_id : 'trace1' , start_timestamp : 1234 } ,
1059+ { span_id : 'span3' , trace_id : 'trace1' , start_timestamp : 1234 } ,
1060+ ] ,
1061+ } ) ;
1062+
1063+ expect ( beforeSendTransaction ) . toHaveBeenCalled ( ) ;
1064+ expect ( TestClient . instance ! . event ! . spans ?. length ) . toBe ( 1 ) ;
1065+
1066+ expect ( client [ '_outcomes' ] ) . toEqual ( { 'before_send:span' : 2 } ) ;
1067+ } ) ;
1068+
10451069 test ( 'calls `beforeSendSpan` and uses the modified spans' , ( ) => {
10461070 expect . assertions ( 3 ) ;
10471071
@@ -1120,8 +1144,6 @@ describe('BaseClient', () => {
11201144 } ) ;
11211145
11221146 test ( 'calls `beforeSendSpan` and discards the span' , ( ) => {
1123- expect . assertions ( 2 ) ;
1124-
11251147 const beforeSendSpan = jest . fn ( ( ) => null ) ;
11261148 const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , beforeSendSpan } ) ;
11271149 const client = new TestClient ( options ) ;
@@ -1149,6 +1171,7 @@ describe('BaseClient', () => {
11491171 expect ( beforeSendSpan ) . toHaveBeenCalledTimes ( 2 ) ;
11501172 const capturedEvent = TestClient . instance ! . event ! ;
11511173 expect ( capturedEvent . spans ) . toHaveLength ( 0 ) ;
1174+ expect ( client [ '_outcomes' ] ) . toEqual ( { 'before_send:span' : 2 } ) ;
11521175 } ) ;
11531176
11541177 test ( 'calls `beforeSend` and logs info about invalid return value' , ( ) => {
@@ -2017,6 +2040,7 @@ describe('BaseClient', () => {
20172040
20182041 describe ( 'hook removal with `on`' , ( ) => {
20192042 it ( 'should return a cleanup function that, when executed, unregisters a hook' , async ( ) => {
2043+ jest . useFakeTimers ( ) ;
20202044 expect . assertions ( 8 ) ;
20212045
20222046 const client = new TestClient (
0 commit comments