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 ' ;
3
3
4
4
import { makeUnhandledPromiseHandler , onUnhandledRejectionIntegration } from '../src/integrations/onunhandledrejection' ;
5
5
6
6
// 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
7
7
global . console . warn = ( ) => null ;
8
8
global . console . error = ( ) => null ;
9
9
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
-
21
10
describe ( 'unhandled promises' , ( ) => {
22
11
test ( 'install global listener' , ( ) => {
12
+ const client = { getOptions : ( ) => ( { } ) } as unknown as Client ;
13
+ SentryCore . setCurrentClient ( client ) ;
14
+
23
15
const integration = onUnhandledRejectionIntegration ( ) ;
24
16
integration . setup ! ( client ) ;
25
17
expect ( process . listeners ( 'unhandledRejection' ) ) . toHaveLength ( 1 ) ;
26
18
} ) ;
27
19
28
20
test ( 'makeUnhandledPromiseHandler' , ( ) => {
21
+ const client = { getOptions : ( ) => ( { } ) } as unknown as Client ;
22
+ SentryCore . setCurrentClient ( client ) ;
23
+
29
24
const promise = {
30
25
domain : {
31
26
sentryContext : {
@@ -36,15 +31,15 @@ describe('unhandled promises', () => {
36
31
} ,
37
32
} ;
38
33
39
- const captureException = jest . spyOn ( Hub . prototype , 'captureException' ) ;
34
+ const captureException = jest . spyOn ( SentryCore , 'captureException' ) . mockImplementation ( ( ) => 'test ') ;
40
35
41
36
const handler = makeUnhandledPromiseHandler ( client , {
42
37
mode : 'warn' ,
43
38
} ) ;
44
39
45
40
handler ( 'bla' , promise ) ;
46
41
47
- expect ( captureException . mock . calls [ 0 ] [ 1 ] ) . toEqual ( {
42
+ expect ( captureException ) . toHaveBeenCalledWith ( 'bla' , {
48
43
originalException : {
49
44
domain : {
50
45
sentryContext : {
0 commit comments