-
-
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.
Merge branch 'main' into react-query/test/usePrefetchInfiniteQuery-name
- Loading branch information
Showing
6 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
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
17 changes: 17 additions & 0 deletions
17
packages/react-query/src/__tests__/infiniteQueryOptions.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,17 @@ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
import { infiniteQueryOptions } from '../infiniteQueryOptions' | ||
import type { UseInfiniteQueryOptions } from '../types' | ||
|
||
describe('infiniteQueryOptions', () => { | ||
it('should return the object received as a parameter without any modification.', () => { | ||
const object: UseInfiniteQueryOptions = { | ||
queryKey: ['key'], | ||
queryFn: () => Promise.resolve(5), | ||
getNextPageParam: () => null, | ||
initialPageParam: null, | ||
} | ||
|
||
expect(infiniteQueryOptions(object)).toStrictEqual(object) | ||
}) | ||
}) |
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,14 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { queryOptions } from '../queryOptions' | ||
import type { UseQueryOptions } from '../types' | ||
|
||
describe('queryOptions', () => { | ||
it('should return the object received as a parameter without any modification.', () => { | ||
const object: UseQueryOptions = { | ||
queryKey: ['key'], | ||
queryFn: () => Promise.resolve(5), | ||
} as const | ||
|
||
expect(queryOptions(object)).toStrictEqual(object) | ||
}) | ||
}) |
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() | ||
}) | ||
}) |
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
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