From aa6d3f84dfa0a1f978819999a41b554f8aa51af2 Mon Sep 17 00:00:00 2001 From: Ethan Glover Date: Wed, 13 Nov 2024 01:03:51 -0600 Subject: [PATCH 1/6] docs: Add @tanstack/query/infinite-query-property-order link (#8285) --- docs/eslint/eslint-plugin-query.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/eslint/eslint-plugin-query.md b/docs/eslint/eslint-plugin-query.md index 759a461cd6..47fb0f81ef 100644 --- a/docs/eslint/eslint-plugin-query.md +++ b/docs/eslint/eslint-plugin-query.md @@ -97,3 +97,4 @@ Alternatively, add `@tanstack/query` to the plugins section, and configure the r - [@tanstack/query/no-rest-destructuring](../no-rest-destructuring) - [@tanstack/query/stable-query-client](../stable-query-client) - [@tanstack/query/no-unstable-deps](../no-unstable-deps) +- [@tanstack/query/infinite-query-property-order](../infinite-query-property-order) From 6c9e3f318cfc5c0a89eb90c38231fe0ec4abb8df Mon Sep 17 00:00:00 2001 From: Jonghyeon Ko Date: Wed, 13 Nov 2024 16:05:17 +0900 Subject: [PATCH 2/6] test(react-query): add test case for queryOptions (#8267) * test(react-query): add test case for queryOptions * chore: update --- .../src/__tests__/queryOptions.test.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 packages/react-query/src/__tests__/queryOptions.test.tsx diff --git a/packages/react-query/src/__tests__/queryOptions.test.tsx b/packages/react-query/src/__tests__/queryOptions.test.tsx new file mode 100644 index 0000000000..28e539690b --- /dev/null +++ b/packages/react-query/src/__tests__/queryOptions.test.tsx @@ -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) + }) +}) From c2b435dcd91a7df248ac5d6d6b928f4bea79b2b6 Mon Sep 17 00:00:00 2001 From: Jonghyeon Ko Date: Wed, 13 Nov 2024 16:05:42 +0900 Subject: [PATCH 3/6] test(react-query): add test case for infiniteQueryOptions (#8268) --- .../src/__tests__/infiniteQueryOptions.test.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 packages/react-query/src/__tests__/infiniteQueryOptions.test.tsx diff --git a/packages/react-query/src/__tests__/infiniteQueryOptions.test.tsx b/packages/react-query/src/__tests__/infiniteQueryOptions.test.tsx new file mode 100644 index 0000000000..3e876fd5d0 --- /dev/null +++ b/packages/react-query/src/__tests__/infiniteQueryOptions.test.tsx @@ -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) + }) +}) From e802711e7bc2efe97a35130cebfc30745f0f113c Mon Sep 17 00:00:00 2001 From: Jonghyeon Ko Date: Wed, 13 Nov 2024 16:06:15 +0900 Subject: [PATCH 4/6] test(react-query): add test case for useSuspenseQuery accept skipToken as queryFn (#8269) --- .../src/__tests__/useSuspenseQuery.test.tsx | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packages/react-query/src/__tests__/useSuspenseQuery.test.tsx b/packages/react-query/src/__tests__/useSuspenseQuery.test.tsx index af2f376ee8..003655ec1d 100644 --- a/packages/react-query/src/__tests__/useSuspenseQuery.test.tsx +++ b/packages/react-query/src/__tests__/useSuspenseQuery.test.tsx @@ -5,6 +5,7 @@ import { ErrorBoundary } from 'react-error-boundary' import { QueryCache, QueryErrorResetBoundary, + skipToken, useQueryErrorResetBoundary, useSuspenseInfiniteQuery, useSuspenseQuery, @@ -870,4 +871,36 @@ describe('useSuspenseQuery', () => { await waitFor(() => rendered.getByText('loading')) await waitFor(() => rendered.getByText('data: 2')) }) + + it('should log an error when skipToken is passed as queryFn', () => { + const consoleErrorSpy = vi + .spyOn(console, 'error') + .mockImplementation(() => {}) + const key = queryKey() + + function Page() { + useSuspenseQuery({ + queryKey: key, + // @ts-expect-error + queryFn: Math.random() >= 0 ? skipToken : () => Promise.resolve(5), + }) + + return null + } + + function App() { + return ( + + + + ) + } + + renderWithClient(queryClient, ) + + expect(consoleErrorSpy).toHaveBeenCalledWith( + 'skipToken is not allowed for useSuspenseQuery', + ) + consoleErrorSpy.mockRestore() + }) }) From ebd4c2b4edcd605772139468d94334b8a3f1aa92 Mon Sep 17 00:00:00 2001 From: Jonghyeon Ko Date: Wed, 13 Nov 2024 16:07:00 +0900 Subject: [PATCH 5/6] test(react-query): add test case for useSuspenseInfiniteQuery accept skipToken as queryFn (#8270) --- .../useSuspenseInfiniteQuery.test.tsx | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 packages/react-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx diff --git a/packages/react-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx b/packages/react-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx new file mode 100644 index 0000000000..b5d7b4a49d --- /dev/null +++ b/packages/react-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx @@ -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 ( + + + + ) + } + + renderWithClient(queryClient, ) + + expect(consoleErrorSpy).toHaveBeenCalledWith( + 'skipToken is not allowed for useSuspenseInfiniteQuery', + ) + consoleErrorSpy.mockRestore() + }) +}) From 8d1f5429e1538b4c4e39703bde93843bb97a544e Mon Sep 17 00:00:00 2001 From: Jonghyeon Ko Date: Wed, 13 Nov 2024 16:07:35 +0900 Subject: [PATCH 6/6] test(react-query): add test case for useSuspenseQueries accept skipToken as queryFn (#8271) --- .../src/__tests__/useSuspenseQueries.test.tsx | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/react-query/src/__tests__/useSuspenseQueries.test.tsx b/packages/react-query/src/__tests__/useSuspenseQueries.test.tsx index ba15741ade..c97f01f12e 100644 --- a/packages/react-query/src/__tests__/useSuspenseQueries.test.tsx +++ b/packages/react-query/src/__tests__/useSuspenseQueries.test.tsx @@ -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 '..' @@ -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 ( + + + + ) + } + + renderWithClient(queryClient, ) + + expect(consoleErrorSpy).toHaveBeenCalledWith( + 'skipToken is not allowed for useSuspenseQueries', + ) + consoleErrorSpy.mockRestore() + }) })