Skip to content

Commit 424ff83

Browse files
committed
fix(react): use new captureException API
1 parent 1d85628 commit 424ff83

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

packages/react/src/errorboundary.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
3535
public state: ErrorBoundaryState = INITIAL_STATE;
3636

3737
public componentDidCatch(error: Error, { componentStack }: React.ErrorInfo): void {
38-
Sentry.withScope(scope => {
39-
scope.setExtra('componentStack', componentStack);
40-
Sentry.captureException(error);
41-
});
38+
Sentry.captureException(error, { contexts: { componentStack } });
4239
const { onError, showDialog, dialogOptions } = this.props;
4340
if (onError) {
4441
onError(error, componentStack);

packages/react/test/errorboundary.test.tsx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,16 @@ import * as React from 'react';
33

44
import { ErrorBoundary, ErrorBoundaryProps, FALLBACK_ERR_MESSAGE } from '../src/errorboundary';
55

6-
const mockSetExtra = jest.fn();
76
const mockCaptureException = jest.fn();
87
const mockShowReportDialog = jest.fn();
98

109
jest.mock('@sentry/browser', () => ({
11-
captureException: (err: any) => {
12-
mockCaptureException(err);
10+
captureException: (err: any, ctx: any) => {
11+
mockCaptureException(err, ctx);
1312
},
1413
showReportDialog: (options: any) => {
1514
mockShowReportDialog(options);
1615
},
17-
withScope: (callback: Function) => {
18-
callback({
19-
setExtra: mockSetExtra,
20-
});
21-
},
2216
}));
2317

2418
const TestApp: React.FC<ErrorBoundaryProps> = ({ children, ...props }) => {
@@ -45,7 +39,6 @@ describe('ErrorBoundary', () => {
4539

4640
afterEach(() => {
4741
consoleErrorSpy.mockClear();
48-
mockSetExtra.mockClear();
4942
mockCaptureException.mockClear();
5043
mockShowReportDialog.mockClear();
5144
});
@@ -179,7 +172,6 @@ describe('ErrorBoundary', () => {
179172

180173
expect(mockOnError).toHaveBeenCalledTimes(0);
181174
expect(mockCaptureException).toHaveBeenCalledTimes(0);
182-
expect(mockSetExtra).toHaveBeenCalledTimes(0);
183175

184176
const btn = screen.getByTestId('errorBtn');
185177
fireEvent.click(btn);
@@ -188,10 +180,9 @@ describe('ErrorBoundary', () => {
188180
expect(mockOnError).toHaveBeenCalledWith(expect.any(Error), expect.any(String));
189181

190182
expect(mockCaptureException).toHaveBeenCalledTimes(1);
191-
expect(mockCaptureException).toHaveBeenCalledWith(expect.any(Error));
192-
193-
expect(mockSetExtra).toHaveBeenCalledTimes(1);
194-
expect(mockSetExtra).toHaveBeenCalledWith('componentStack', expect.any(String));
183+
expect(mockCaptureException).toHaveBeenCalledWith(expect.any(Error), {
184+
contexts: { componentStack: expect.any(String) },
185+
});
195186
});
196187

197188
it('shows a Sentry Report Dialog with correct options', () => {

0 commit comments

Comments
 (0)