Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/react/tests/QueryResetErrorBoundary.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,65 @@ describe('QueryErrorResetBoundary', () => {
consoleMock.mockRestore()
})

it('should throw error if query is disabled and manually refetched', async () => {
const key = queryKey()

const consoleMock = mockConsoleError()

function Page() {
const { data, refetch, status } = useQuery(
key,
async () => {
throw new Error('Error')
},
{
retry: false,
enabled: false,
useErrorBoundary: true,
}
)

return (
<div>
<button onClick={() => refetch()}>refetch</button>
<div>status: {status}</div>
<div>{data}</div>
</div>
)
}

const rendered = renderWithClient(
queryClient,
<QueryErrorResetBoundary>
{({ reset }) => (
<ErrorBoundary
onReset={reset}
fallbackRender={({ resetErrorBoundary }) => (
<div>
<div>error boundary</div>
<button
onClick={() => {
resetErrorBoundary()
}}
>
retry
</button>
</div>
)}
>
<Page />
</ErrorBoundary>
)}
</QueryErrorResetBoundary>
)

await waitFor(() => rendered.getByText('status: idle'))
rendered.getByRole('button', { name: /refetch/i }).click()
await waitFor(() => rendered.getByText('error boundary'))

consoleMock.mockRestore()
})

it('should not retry fetch if the reset error boundary has not been reset', async () => {
const key = queryKey()

Expand Down
2 changes: 1 addition & 1 deletion src/react/useBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function useBaseQuery<
// Handle error boundary
if (
result.isError &&
defaultedOptions.enabled !== false &&
!errorResetBoundary.isReset() &&
!result.isFetching &&
shouldThrowError(
defaultedOptions.suspense,
Expand Down