From 424ff831af0ce828c05aab49f91852e15d8daa0c Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Fri, 5 Jun 2020 08:39:23 -0400 Subject: [PATCH] fix(react): use new captureException API --- packages/react/src/errorboundary.tsx | 5 +---- packages/react/test/errorboundary.test.tsx | 19 +++++-------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/packages/react/src/errorboundary.tsx b/packages/react/src/errorboundary.tsx index 677ee6382d4a..b75569b1d1c4 100644 --- a/packages/react/src/errorboundary.tsx +++ b/packages/react/src/errorboundary.tsx @@ -35,10 +35,7 @@ class ErrorBoundary extends React.Component { - scope.setExtra('componentStack', componentStack); - Sentry.captureException(error); - }); + Sentry.captureException(error, { contexts: { componentStack } }); const { onError, showDialog, dialogOptions } = this.props; if (onError) { onError(error, componentStack); diff --git a/packages/react/test/errorboundary.test.tsx b/packages/react/test/errorboundary.test.tsx index 3066f1b56562..7bc0e51e14db 100644 --- a/packages/react/test/errorboundary.test.tsx +++ b/packages/react/test/errorboundary.test.tsx @@ -3,22 +3,16 @@ import * as React from 'react'; import { ErrorBoundary, ErrorBoundaryProps, FALLBACK_ERR_MESSAGE } from '../src/errorboundary'; -const mockSetExtra = jest.fn(); const mockCaptureException = jest.fn(); const mockShowReportDialog = jest.fn(); jest.mock('@sentry/browser', () => ({ - captureException: (err: any) => { - mockCaptureException(err); + captureException: (err: any, ctx: any) => { + mockCaptureException(err, ctx); }, showReportDialog: (options: any) => { mockShowReportDialog(options); }, - withScope: (callback: Function) => { - callback({ - setExtra: mockSetExtra, - }); - }, })); const TestApp: React.FC = ({ children, ...props }) => { @@ -45,7 +39,6 @@ describe('ErrorBoundary', () => { afterEach(() => { consoleErrorSpy.mockClear(); - mockSetExtra.mockClear(); mockCaptureException.mockClear(); mockShowReportDialog.mockClear(); }); @@ -179,7 +172,6 @@ describe('ErrorBoundary', () => { expect(mockOnError).toHaveBeenCalledTimes(0); expect(mockCaptureException).toHaveBeenCalledTimes(0); - expect(mockSetExtra).toHaveBeenCalledTimes(0); const btn = screen.getByTestId('errorBtn'); fireEvent.click(btn); @@ -188,10 +180,9 @@ describe('ErrorBoundary', () => { expect(mockOnError).toHaveBeenCalledWith(expect.any(Error), expect.any(String)); expect(mockCaptureException).toHaveBeenCalledTimes(1); - expect(mockCaptureException).toHaveBeenCalledWith(expect.any(Error)); - - expect(mockSetExtra).toHaveBeenCalledTimes(1); - expect(mockSetExtra).toHaveBeenCalledWith('componentStack', expect.any(String)); + expect(mockCaptureException).toHaveBeenCalledWith(expect.any(Error), { + contexts: { componentStack: expect.any(String) }, + }); }); it('shows a Sentry Report Dialog with correct options', () => {