Skip to content

Commit

Permalink
test(react-query): add test case for useSuspenseInfiniteQuery accept …
Browse files Browse the repository at this point in the history
…skipToken as queryFn (#8270)
  • Loading branch information
manudeli authored Nov 13, 2024
1 parent e802711 commit ebd4c2b
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { describe, expect, it, vi } from 'vitest'
import * as React from 'react'
import { QueryCache, skipToken, useSuspenseInfiniteQuery } from '..'
import { createQueryClient, queryKey, renderWithClient } from './utils'

describe('useSuspenseInfiniteQuery', () => {
const queryCache = new QueryCache()
const queryClient = createQueryClient({ queryCache })

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

function Page() {
useSuspenseInfiniteQuery({
queryKey: key,
initialPageParam: 1,
getNextPageParam: () => 1,
// @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 useSuspenseInfiniteQuery',
)
consoleErrorSpy.mockRestore()
})
})

0 comments on commit ebd4c2b

Please sign in to comment.