1
+ import { BaseClient } from '@sentry/core' ;
1
2
import { RewriteFrames } from '@sentry/integrations' ;
2
3
import * as SentryNode from '@sentry/node' ;
3
4
import { getCurrentHub , NodeClient } from '@sentry/node' ;
@@ -16,11 +17,12 @@ const global = getGlobalObject();
16
17
( global as typeof global & { __rewriteFramesDistDir__ : string } ) . __rewriteFramesDistDir__ = '.next' ;
17
18
18
19
const nodeInit = jest . spyOn ( SentryNode , 'init' ) ;
20
+ const captureEvent = jest . spyOn ( BaseClient . prototype , 'captureEvent' ) ;
19
21
const logError = jest . spyOn ( logger , 'error' ) ;
20
22
21
23
describe ( 'Server init()' , ( ) => {
22
24
afterEach ( ( ) => {
23
- nodeInit . mockClear ( ) ;
25
+ jest . clearAllMocks ( ) ;
24
26
global . __SENTRY__ . hub = undefined ;
25
27
} ) ;
26
28
@@ -93,10 +95,14 @@ describe('Server init()', () => {
93
95
dsn : 'https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012' ,
94
96
tracesSampleRate : 1.0 ,
95
97
} ) ;
98
+ const hub = getCurrentHub ( ) ;
99
+ const sendEvent = jest . spyOn ( hub . getClient ( ) ! . getTransport ! ( ) , 'sendEvent' ) ;
96
100
97
- const transaction = getCurrentHub ( ) . startTransaction ( { name : '/404' } ) ;
101
+ const transaction = hub . startTransaction ( { name : '/404' } ) ;
98
102
transaction . finish ( ) ;
99
103
104
+ expect ( sendEvent ) . not . toHaveBeenCalled ( ) ;
105
+ expect ( captureEvent . mock . results [ 0 ] . value ) . toBeUndefined ( ) ;
100
106
expect ( logError ) . toHaveBeenCalledWith ( new SentryError ( 'An event processor returned null, will not send event.' ) ) ;
101
107
} ) ;
102
108
0 commit comments