1+ import { BaseClient } from '@sentry/core' ;
12import { RewriteFrames } from '@sentry/integrations' ;
23import * as SentryNode from '@sentry/node' ;
34import { getCurrentHub , NodeClient } from '@sentry/node' ;
@@ -16,11 +17,12 @@ const global = getGlobalObject();
1617( global as typeof global & { __rewriteFramesDistDir__ : string } ) . __rewriteFramesDistDir__ = '.next' ;
1718
1819const nodeInit = jest . spyOn ( SentryNode , 'init' ) ;
20+ const captureEvent = jest . spyOn ( BaseClient . prototype , 'captureEvent' ) ;
1921const logError = jest . spyOn ( logger , 'error' ) ;
2022
2123describe ( 'Server init()' , ( ) => {
2224 afterEach ( ( ) => {
23- nodeInit . mockClear ( ) ;
25+ jest . clearAllMocks ( ) ;
2426 global . __SENTRY__ . hub = undefined ;
2527 } ) ;
2628
@@ -93,10 +95,14 @@ describe('Server init()', () => {
9395 dsn :
'https://[email protected] /12312012' , 9496 tracesSampleRate : 1.0 ,
9597 } ) ;
98+ const hub = getCurrentHub ( ) ;
99+ const sendEvent = jest . spyOn ( hub . getClient ( ) ! . getTransport ! ( ) , 'sendEvent' ) ;
96100
97- const transaction = getCurrentHub ( ) . startTransaction ( { name : '/404' } ) ;
101+ const transaction = hub . startTransaction ( { name : '/404' } ) ;
98102 transaction . finish ( ) ;
99103
104+ expect ( sendEvent ) . not . toHaveBeenCalled ( ) ;
105+ expect ( captureEvent . mock . results [ 0 ] . value ) . toBeUndefined ( ) ;
100106 expect ( logError ) . toHaveBeenCalledWith ( new SentryError ( 'An event processor returned null, will not send event.' ) ) ;
101107 } ) ;
102108
0 commit comments