Skip to content

Commit

Permalink
test(react-query): add test case for useSuspenseQuery accept skipToke…
Browse files Browse the repository at this point in the history
…n as queryFn (#8269)
  • Loading branch information
manudeli authored Nov 13, 2024
1 parent c2b435d commit e802711
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/react-query/src/__tests__/useSuspenseQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ErrorBoundary } from 'react-error-boundary'
import {
QueryCache,
QueryErrorResetBoundary,
skipToken,
useQueryErrorResetBoundary,
useSuspenseInfiniteQuery,
useSuspenseQuery,
Expand Down Expand Up @@ -870,4 +871,36 @@ describe('useSuspenseQuery', () => {
await waitFor(() => rendered.getByText('loading'))
await waitFor(() => rendered.getByText('data: 2'))
})

it('should log an error when skipToken is passed as queryFn', () => {
const consoleErrorSpy = vi
.spyOn(console, 'error')
.mockImplementation(() => {})
const key = queryKey()

function Page() {
useSuspenseQuery({
queryKey: key,
// @ts-expect-error
queryFn: Math.random() >= 0 ? skipToken : () => Promise.resolve(5),
})

return null
}

function App() {
return (
<React.Suspense fallback="Loading...">
<Page />
</React.Suspense>
)
}

renderWithClient(queryClient, <App />)

expect(consoleErrorSpy).toHaveBeenCalledWith(
'skipToken is not allowed for useSuspenseQuery',
)
consoleErrorSpy.mockRestore()
})
})

0 comments on commit e802711

Please sign in to comment.