Skip to content

Commit

Permalink
test(react-query): add test case for useSuspenseQueries accept skipTo…
Browse files Browse the repository at this point in the history
…ken as queryFn (#8271)
  • Loading branch information
manudeli authored Nov 13, 2024
1 parent ebd4c2b commit 8d1f542
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion packages/react-query/src/__tests__/useSuspenseQueries.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { act, fireEvent, render, waitFor } from '@testing-library/react'
import * as React from 'react'
import { ErrorBoundary } from 'react-error-boundary'
import { useSuspenseQueries, useSuspenseQuery } from '..'
import { skipToken, useSuspenseQueries, useSuspenseQuery } from '..'
import { createQueryClient, queryKey, renderWithClient, sleep } from './utils'
import type { UseSuspenseQueryOptions } from '..'

Expand Down Expand Up @@ -658,4 +658,40 @@ describe('useSuspenseQueries 2', () => {
expect(queryClient.getQueryData(key)).toBe(undefined)
})
})

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

function Page() {
useSuspenseQueries({
queries: [
{
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 useSuspenseQueries',
)
consoleErrorSpy.mockRestore()
})
})

0 comments on commit 8d1f542

Please sign in to comment.