mirror of
https://github.com/langgenius/dify.git
synced 2026-07-26 14:18:35 +08:00
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: GareArc <garethcxy@dify.ai>
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { QueryErrorResetBoundary } from '@tanstack/react-query'
|
|
import { render, screen } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import CommonLayoutError from '@/app/(commonLayout)/error'
|
|
import AppError from '@/app/error'
|
|
|
|
describe('route error recovery', () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks()
|
|
})
|
|
|
|
it.each([
|
|
{
|
|
name: 'root error',
|
|
renderError: (retry: () => void) => <AppError error={new Error('failed')} reset={retry} />,
|
|
},
|
|
{
|
|
name: 'common layout error',
|
|
renderError: (retry: () => void) => (
|
|
<CommonLayoutError error={new Error('failed')} unstable_retry={retry} />
|
|
),
|
|
},
|
|
])('resets failed queries before retrying the $name', async ({ renderError }) => {
|
|
const user = userEvent.setup()
|
|
const retry = vi.fn()
|
|
vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
|
|
render(
|
|
<QueryErrorResetBoundary>
|
|
{({ isReset }) => renderError(() => retry(isReset()))}
|
|
</QueryErrorResetBoundary>,
|
|
)
|
|
|
|
await user.click(screen.getByRole('button', { name: 'common.errorBoundary.tryAgain' }))
|
|
|
|
expect(retry).toHaveBeenCalledWith(true)
|
|
})
|
|
})
|