Skip to content

Commit bd15719

Browse files
committed
test(react): add test case
1 parent 3c90039 commit bd15719

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/react/src/ErrorBoundary.spec.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,26 @@ describe('<ErrorBoundary/>', () => {
187187
await waitFor(() => expect(screen.queryByText(`${ERROR_MESSAGE} of Parent`)).toBeInTheDocument())
188188
})
189189

190+
it('should re-throw error if not shouldCatch error in children without rendering fallback', async () => {
191+
const onErrorParent = vi.fn()
192+
const onErrorChild = vi.fn()
193+
const Fallback = vi.fn()
194+
195+
render(
196+
<ErrorBoundary fallback={({ error }) => <>{error.message} of Parent</>} onError={onErrorParent}>
197+
<ErrorBoundary shouldCatch={false} fallback={Fallback} onError={onErrorChild}>
198+
{createElement(() => {
199+
throw new Error(ERROR_MESSAGE)
200+
})}
201+
</ErrorBoundary>
202+
</ErrorBoundary>
203+
)
204+
205+
expect(onErrorChild).toBeCalledTimes(0)
206+
expect(onErrorParent).toBeCalledTimes(1)
207+
await waitFor(() => expect(screen.queryByText(`${ERROR_MESSAGE} of Parent`)).toBeInTheDocument())
208+
})
209+
190210
it.each([
191211
{
192212
childCalledTimes: 0,

0 commit comments

Comments
 (0)