Skip to content

Commit

Permalink
ref: Change name to beforeCapture
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad committed Jul 20, 2020
1 parent 13e1f9b commit 486f402
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -5,7 +5,7 @@
- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
- [react] feat: Export `createReduxEnhancer` to log redux actions as breadcrumbs, and attach state as an extra. (#2717)
- [tracing] feat: `Add @sentry/tracing` (#2719)
- [react] feat: Add `beforeSend` option to ErrorBoundary
- [react] feat: Add `beforeCapture` option to ErrorBoundary (#2753)

## 5.19.2

Expand Down
8 changes: 4 additions & 4 deletions packages/react/src/errorboundary.tsx
Expand Up @@ -39,7 +39,7 @@ export type ErrorBoundaryProps = {
/** Called on componentWillUnmount() */
onUnmount?(error: Error | null, componentStack: string | null, eventId: string | null): void;
/** Called before error is sent to Sentry, allows for you to add tags or context using the scope */
beforeSend?(scope: Scope, error: Error | null, componentStack: string | null): void;
beforeCapture?(scope: Scope, error: Error | null, componentStack: string | null): void;
};

type ErrorBoundaryState = {
Expand All @@ -62,11 +62,11 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
public state: ErrorBoundaryState = INITIAL_STATE;

public componentDidCatch(error: Error, { componentStack }: React.ErrorInfo): void {
const { beforeSend, onError, showDialog, dialogOptions } = this.props;
const { beforeCapture, onError, showDialog, dialogOptions } = this.props;

withScope(scope => {
if (beforeSend) {
beforeSend(scope, error, componentStack);
if (beforeCapture) {
beforeCapture(scope, error, componentStack);
}
const eventId = captureException(error, { contexts: { react: { componentStack } } });
if (onError) {
Expand Down
16 changes: 8 additions & 8 deletions packages/react/test/errorboundary.test.tsx
Expand Up @@ -202,28 +202,28 @@ describe('ErrorBoundary', () => {
});
});

it('calls `beforeSend()` when an error occurs', () => {
const mockBeforeSend = jest.fn();
it('calls `beforeCapture()` when an error occurs', () => {
const mockBeforeCapture = jest.fn();

const testBeforeSend = (...args: any[]) => {
const testBeforeCapture = (...args: any[]) => {
expect(mockCaptureException).toHaveBeenCalledTimes(0);
mockBeforeSend(...args);
mockBeforeCapture(...args);
};

render(
<TestApp fallback={<p>You have hit an error</p>} beforeSend={testBeforeSend}>
<TestApp fallback={<p>You have hit an error</p>} beforeCapture={testBeforeCapture}>
<h1>children</h1>
</TestApp>,
);

expect(mockBeforeSend).toHaveBeenCalledTimes(0);
expect(mockBeforeCapture).toHaveBeenCalledTimes(0);
expect(mockCaptureException).toHaveBeenCalledTimes(0);

const btn = screen.getByTestId('errorBtn');
fireEvent.click(btn);

expect(mockBeforeSend).toHaveBeenCalledTimes(1);
expect(mockBeforeSend).toHaveBeenLastCalledWith(expect.any(Scope), expect.any(Error), expect.any(String));
expect(mockBeforeCapture).toHaveBeenCalledTimes(1);
expect(mockBeforeCapture).toHaveBeenLastCalledWith(expect.any(Scope), expect.any(Error), expect.any(String));
expect(mockCaptureException).toHaveBeenCalledTimes(1);
});

Expand Down

0 comments on commit 486f402

Please sign in to comment.