@@ -4,14 +4,15 @@ import { Scope } from '@sentry/svelte';
4
4
// adding a custom resolver, which will take too much time.
5
5
// eslint-disable-next-line import/no-unresolved
6
6
import type { HandleClientError , NavigationEvent } from '@sveltejs/kit' ;
7
+ import { vi } from 'vitest' ;
7
8
8
9
import { handleErrorWithSentry } from '../../src/client/handleError' ;
9
10
10
- const mockCaptureException = jest . fn ( ) ;
11
+ const mockCaptureException = vi . fn ( ) ;
11
12
let mockScope = new Scope ( ) ;
12
13
13
- jest . mock ( '@sentry/svelte' , ( ) => {
14
- const original = jest . requireActual ( '@sentry/core' ) ;
14
+ vi . mock ( '@sentry/svelte' , async ( ) => {
15
+ const original = ( await vi . importActual ( '@sentry/core' ) ) as any ;
15
16
return {
16
17
...original ,
17
18
captureException : ( err : unknown , cb : ( arg0 : unknown ) => unknown ) => {
@@ -22,10 +23,10 @@ jest.mock('@sentry/svelte', () => {
22
23
} ;
23
24
} ) ;
24
25
25
- const mockAddExceptionMechanism = jest . fn ( ) ;
26
+ const mockAddExceptionMechanism = vi . fn ( ) ;
26
27
27
- jest . mock ( '@sentry/utils' , ( ) => {
28
- const original = jest . requireActual ( '@sentry/utils' ) ;
28
+ vi . mock ( '@sentry/utils' , async ( ) => {
29
+ const original = ( await vi . importActual ( '@sentry/utils' ) ) as any ;
29
30
return {
30
31
...original ,
31
32
addExceptionMechanism : ( ...args : unknown [ ] ) => mockAddExceptionMechanism ( ...args ) ,
@@ -68,15 +69,15 @@ describe('handleError', () => {
68
69
it ( 'calls captureException' , async ( ) => {
69
70
const wrappedHandleError = handleErrorWithSentry ( handleError ) ;
70
71
const mockError = new Error ( 'test' ) ;
71
- const returnVal = await wrappedHandleError ( { error : mockError , event : navigationEvent } ) ;
72
+ const returnVal = ( await wrappedHandleError ( { error : mockError , event : navigationEvent } ) ) as any ;
72
73
73
- expect ( returnVal ! . message ) . toEqual ( 'Whoops!' ) ;
74
+ expect ( returnVal . message ) . toEqual ( 'Whoops!' ) ;
74
75
expect ( mockCaptureException ) . toHaveBeenCalledTimes ( 1 ) ;
75
76
expect ( mockCaptureException ) . toHaveBeenCalledWith ( mockError , expect . any ( Function ) ) ;
76
77
} ) ;
77
78
78
79
it ( 'adds an exception mechanism' , async ( ) => {
79
- const addEventProcessorSpy = jest . spyOn ( mockScope , 'addEventProcessor' ) . mockImplementationOnce ( callback => {
80
+ const addEventProcessorSpy = vi . spyOn ( mockScope , 'addEventProcessor' ) . mockImplementationOnce ( callback => {
80
81
void callback ( { } , { event_id : 'fake-event-id' } ) ;
81
82
return mockScope ;
82
83
} ) ;
0 commit comments