Skip to content

Commit

Permalink
chore: refactor for uplifting react-error-boundary to v5
Browse files Browse the repository at this point in the history
Signed-off-by: hainenber <[email protected]>
  • Loading branch information
hainenber committed Jan 5, 2025
1 parent e311bc1 commit 44a0010
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 22 deletions.
35 changes: 22 additions & 13 deletions superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion superset-frontend/packages/superset-ui-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"lodash": "^4.17.21",
"math-expression-evaluator": "^1.3.8",
"pretty-ms": "^9.2.0",
"react-error-boundary": "^1.2.5",
"react-error-boundary": "^5.0.0",
"react-markdown": "^8.0.7",
"rehype-raw": "^7.0.0",
"rehype-sanitize": "^6.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
Fragment,
} from 'react';

import ErrorBoundary, {
import {
ErrorBoundary,
ErrorBoundaryProps,
FallbackProps,
} from 'react-error-boundary';
Expand All @@ -46,7 +47,9 @@ const defaultProps = {
enableNoResults: true,
};

export type FallbackPropsWithDimension = FallbackProps & Partial<Dimension>;
export type FallbackPropsWithDimension = FallbackProps & {
componentStack?: string;
} & Partial<Dimension>;

export type WrapperProps = Dimension & {
children: ReactNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { ThemeProvider, supersetTheme } from '../../../src/style';

import FallbackComponent from '../../../src/chart/components/FallbackComponent';

const renderWithTheme = (props: FallbackProps) =>
const renderWithTheme = (props: FallbackProps & { componentStack?: string }) =>
render(
<ThemeProvider theme={supersetTheme}>
<FallbackComponent {...props} />
Expand All @@ -38,23 +38,34 @@ test('renders error and stack trace', () => {
const { getByText } = renderWithTheme({
componentStack: STACK_TRACE,
error: ERROR,
resetErrorBoundary: jest.fn(),
});
expect(getByText('Error: CaffeineOverLoadException')).toBeInTheDocument();
expect(getByText('Error at line 1: x.drink(coffee)')).toBeInTheDocument();
});

test('renders error only', () => {
const { getByText } = renderWithTheme({ error: ERROR });
const { getByText } = renderWithTheme({
error: ERROR,
resetErrorBoundary: jest.fn(),
});
expect(getByText('Error: CaffeineOverLoadException')).toBeInTheDocument();
});

test('renders stacktrace only', () => {
const { getByText } = renderWithTheme({ componentStack: STACK_TRACE });
const { getByText } = renderWithTheme({
componentStack: STACK_TRACE,
error: undefined,
resetErrorBoundary: jest.fn(),
});
expect(getByText('Unknown Error')).toBeInTheDocument();
expect(getByText('Error at line 1: x.drink(coffee)')).toBeInTheDocument();
});

test('renders when nothing is given', () => {
const { getByText } = renderWithTheme({});
const { getByText } = renderWithTheme({
error: undefined,
resetErrorBoundary: jest.fn(),
});
expect(getByText('Unknown Error')).toBeInTheDocument();
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { ReactElement } from 'react';
import mockConsole, { RestoreConsole } from 'jest-mock-console';
import { triggerResizeObserver } from 'resize-observer-polyfill';
import ErrorBoundary from 'react-error-boundary';
import { ErrorBoundary } from 'react-error-boundary';

import {
promiseTimeout,
Expand Down Expand Up @@ -165,7 +165,7 @@ describe('SuperChart', () => {
const inactiveErrorHandler = jest.fn();
const activeErrorHandler = jest.fn();
mount(
<ErrorBoundary onError={activeErrorHandler}>
<ErrorBoundary onError={activeErrorHandler} fallbackRender={() => null}>
<SuperChart
disableErrorBoundary
chartType={ChartKeys.BUGGY}
Expand Down

0 comments on commit 44a0010

Please sign in to comment.