Skip to content

Commit e802711

Browse files
authored
test(react-query): add test case for useSuspenseQuery accept skipToken as queryFn (TanStack#8269)
1 parent c2b435d commit e802711

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

packages/react-query/src/__tests__/useSuspenseQuery.test.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ErrorBoundary } from 'react-error-boundary'
55
import {
66
QueryCache,
77
QueryErrorResetBoundary,
8+
skipToken,
89
useQueryErrorResetBoundary,
910
useSuspenseInfiniteQuery,
1011
useSuspenseQuery,
@@ -870,4 +871,36 @@ describe('useSuspenseQuery', () => {
870871
await waitFor(() => rendered.getByText('loading'))
871872
await waitFor(() => rendered.getByText('data: 2'))
872873
})
874+
875+
it('should log an error when skipToken is passed as queryFn', () => {
876+
const consoleErrorSpy = vi
877+
.spyOn(console, 'error')
878+
.mockImplementation(() => {})
879+
const key = queryKey()
880+
881+
function Page() {
882+
useSuspenseQuery({
883+
queryKey: key,
884+
// @ts-expect-error
885+
queryFn: Math.random() >= 0 ? skipToken : () => Promise.resolve(5),
886+
})
887+
888+
return null
889+
}
890+
891+
function App() {
892+
return (
893+
<React.Suspense fallback="Loading...">
894+
<Page />
895+
</React.Suspense>
896+
)
897+
}
898+
899+
renderWithClient(queryClient, <App />)
900+
901+
expect(consoleErrorSpy).toHaveBeenCalledWith(
902+
'skipToken is not allowed for useSuspenseQuery',
903+
)
904+
consoleErrorSpy.mockRestore()
905+
})
873906
})

0 commit comments

Comments
 (0)