Skip to content

Commit

Permalink
chore: add case to compare with react-error-boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
manudeli committed Jan 9, 2025
1 parent b6ead4e commit be9e879
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"@suspensive/tsconfig": "workspace:*",
"@suspensive/tsup": "workspace:*",
"@types/react": "catalog:react19",
"react": "catalog:react19"
"react": "catalog:react19",
"react-error-boundary": "^5.0.0"
},
"peerDependencies": {
"react": "^18 || ^19"
Expand Down
29 changes: 28 additions & 1 deletion packages/react/src/ErrorBoundary.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { act, render, screen, waitFor } from '@testing-library/react'
import { userEvent } from '@testing-library/user-event'
import ms from 'ms'
import { type ComponentRef, createElement, createRef } from 'react'
import { ErrorBoundary as ReactErrorBoundary } from 'react-error-boundary'
import {
ErrorBoundary,
type ErrorBoundaryFallbackProps,
Expand Down Expand Up @@ -294,7 +295,7 @@ describe('<ErrorBoundary/>', () => {
}
)

it('should re-throw error occurred by fallback', async () => {
it('should re-throw error in fallback', async () => {
render(
<ErrorBoundary fallback={() => <>This is expected</>}>
<ErrorBoundary
Expand All @@ -315,6 +316,32 @@ describe('<ErrorBoundary/>', () => {
await waitFor(() => expect(screen.queryByText("ErrorBoundary's fallback before error")).toBeInTheDocument())
await waitFor(() => expect(screen.queryByText('This is expected')).toBeInTheDocument())
})
it('should not re-throw error in fallback (react-error-boundary)', async () => {
render(
<ReactErrorBoundary fallbackRender={() => <>This is expected</>}>
<ReactErrorBoundary
fallbackRender={() => (
<Throw.Error message={ERROR_MESSAGE} after={100}>
ErrorBoundary(react-error-boundary)'s fallback before error
</Throw.Error>
)}
>
<Throw.Error message={ERROR_MESSAGE} after={100}>
ErrorBoundary(react-error-boundary)'s children before error
</Throw.Error>
</ReactErrorBoundary>
</ReactErrorBoundary>
)

expect(screen.queryByText("ErrorBoundary(react-error-boundary)'s children before error")).toBeInTheDocument()
await waitFor(() =>
expect(screen.queryByText("ErrorBoundary(react-error-boundary)'s fallback before error")).toBeInTheDocument()
)
await waitFor(() => expect(screen.queryByText('This is expected')).not.toBeInTheDocument())
await waitFor(() =>
expect(screen.queryByText("ErrorBoundary(react-error-boundary)'s fallback before error")).toBeInTheDocument()
)
})
})

describe('<ErrorBoundary.Consumer/>', () => {
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit be9e879

Please sign in to comment.