-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(react-query): add test case for useSuspenseInfiniteQuery accept …
…skipToken as queryFn (#8270)
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
packages/react-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) |