1- import { Hub } from '@sentry/core' ;
2- import type { NodeClient } from '../src/client ' ;
1+ import * as SentryCore from '@sentry/core' ;
2+ import type { Client } from '@sentry/types ' ;
33
44import { makeUnhandledPromiseHandler , onUnhandledRejectionIntegration } from '../src/integrations/onunhandledrejection' ;
55
66// don't log the test errors we're going to throw, so at a quick glance it doesn't look like the test itself has failed
77global . console . warn = ( ) => null ;
88global . console . error = ( ) => null ;
99
10- const client = { getOptions : ( ) => ( { } ) } as unknown as NodeClient ;
11-
12- jest . mock ( '@sentry/core' , ( ) => {
13- // we just want to short-circuit it, so dont worry about types
14- const original = jest . requireActual ( '@sentry/core' ) ;
15- return {
16- ...original ,
17- getClient : ( ) => client ,
18- } ;
19- } ) ;
20-
2110describe ( 'unhandled promises' , ( ) => {
2211 test ( 'install global listener' , ( ) => {
12+ const client = { getOptions : ( ) => ( { } ) } as unknown as Client ;
13+ SentryCore . setCurrentClient ( client ) ;
14+
2315 const integration = onUnhandledRejectionIntegration ( ) ;
2416 integration . setup ! ( client ) ;
2517 expect ( process . listeners ( 'unhandledRejection' ) ) . toHaveLength ( 1 ) ;
2618 } ) ;
2719
2820 test ( 'makeUnhandledPromiseHandler' , ( ) => {
21+ const client = { getOptions : ( ) => ( { } ) } as unknown as Client ;
22+ SentryCore . setCurrentClient ( client ) ;
23+
2924 const promise = {
3025 domain : {
3126 sentryContext : {
@@ -36,15 +31,15 @@ describe('unhandled promises', () => {
3631 } ,
3732 } ;
3833
39- const captureException = jest . spyOn ( Hub . prototype , 'captureException' ) ;
34+ const captureException = jest . spyOn ( SentryCore , 'captureException' ) . mockImplementation ( ( ) => 'test ') ;
4035
4136 const handler = makeUnhandledPromiseHandler ( client , {
4237 mode : 'warn' ,
4338 } ) ;
4439
4540 handler ( 'bla' , promise ) ;
4641
47- expect ( captureException . mock . calls [ 0 ] [ 1 ] ) . toEqual ( {
42+ expect ( captureException ) . toHaveBeenCalledWith ( 'bla' , {
4843 originalException : {
4944 domain : {
5045 sentryContext : {
0 commit comments