Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(react-query): add test case for useSuspenseInfiniteQuery accept skipToken as queryFn #8270

Merged
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
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()
})
})
Loading