-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathsentryOnError.test.ts
More file actions
38 lines (30 loc) · 1.32 KB
/
sentryOnError.test.ts
File metadata and controls
38 lines (30 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import * as SentryCore from '@sentry/core';
import * as SentryReact from '@sentry/react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { sentryOnError } from '../../src/client/sentryOnError';
const captureReactExceptionSpy = vi.spyOn(SentryReact, 'captureReactException').mockReturnValue('mock-event-id');
const captureExceptionSpy = vi.spyOn(SentryCore, 'captureException').mockReturnValue('mock-event-id');
describe('sentryOnError', () => {
afterEach(() => {
vi.clearAllMocks();
});
it('calls captureReactException when errorInfo is provided', () => {
const error = new Error('test error');
const errorInfo = { componentStack: '<TestComponent>\n<App>' };
sentryOnError(error, {
errorInfo,
});
expect(captureReactExceptionSpy).toHaveBeenCalledWith(error, errorInfo, {
mechanism: { handled: false, type: 'auto.function.react_router.on_error' },
});
expect(captureExceptionSpy).not.toHaveBeenCalled();
});
it('calls captureException when errorInfo is undefined', () => {
const error = new Error('loader error');
sentryOnError(error, {});
expect(captureExceptionSpy).toHaveBeenCalledWith(error, {
mechanism: { handled: false, type: 'auto.function.react_router.on_error' },
});
expect(captureReactExceptionSpy).not.toHaveBeenCalled();
});
});