From f2bc921aa2e0f8f0d43783bef09b8e12be5cad4d Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Fri, 23 Oct 2026 14:31:29 +0900 Subject: [PATCH 1/2] test(*): rename the 'queryKey' test helper to 'createKey' since it creates keys for both queries and mutations --- .../infinite-query-options.test-d.ts | 26 +- .../__tests__/infinite-query-options.test.ts | 4 +- .../__tests__/inject-infinite-query.test-d.ts | 6 +- .../__tests__/inject-infinite-query.test.ts | 14 +- .../src/__tests__/inject-is-fetching.test.ts | 8 +- .../src/__tests__/inject-is-mutating.test.ts | 8 +- .../__tests__/inject-mutation-state.test.ts | 10 +- .../src/__tests__/inject-mutation.test.ts | 36 +- .../src/__tests__/inject-queries.test-d.ts | 24 +- .../src/__tests__/inject-queries.test.ts | 18 +- .../src/__tests__/inject-query.test-d.ts | 30 +- .../src/__tests__/inject-query.test.ts | 50 +-- .../src/__tests__/mutation-options.test-d.ts | 24 +- .../src/__tests__/mutation-options.test.ts | 22 +- .../src/__tests__/pending-tasks.test.ts | 32 +- .../src/__tests__/query-options.test-d.ts | 32 +- .../with-persist-query-client.test.ts | 12 +- .../src/__tests__/QueryClientProvider.test.ts | 4 +- .../createInfiniteQueryController.test-d.ts | 22 +- .../createInfiniteQueryController.test.ts | 40 +-- .../createMutationController.test.ts | 20 +- .../createQueriesController.test-d.ts | 76 ++-- .../__tests__/createQueriesController.test.ts | 64 ++-- .../__tests__/createQueryController.test-d.ts | 38 +- .../__tests__/createQueryController.test.ts | 84 ++--- .../__tests__/infiniteQueryOptions.test-d.ts | 34 +- .../__tests__/infiniteQueryOptions.test.ts | 4 +- .../src/__tests__/mutationOptions.test-d.ts | 18 +- .../src/__tests__/mutationOptions.test.ts | 20 +- .../src/__tests__/queryOptions.test-d.ts | 48 +-- packages/lit-query/src/__tests__/ssr.test.ts | 16 +- .../src/__tests__/useIsFetching.test.ts | 28 +- .../src/__tests__/useIsMutating.test.ts | 24 +- .../src/__tests__/useMutationState.test.ts | 22 +- .../PersistQueryClientProvider.test.tsx | 4 +- .../src/__tests__/HydrationBoundary.test.tsx | 8 +- .../__tests__/QueryClientProvider.test.tsx | 10 +- .../QueryResetErrorBoundary.test.tsx | 26 +- .../__tests__/fine-grained-persister.test.tsx | 8 +- .../__tests__/infiniteQueryOptions.test-d.tsx | 30 +- .../__tests__/infiniteQueryOptions.test.tsx | 4 +- .../src/__tests__/mutationOptions.test-d.tsx | 24 +- .../src/__tests__/mutationOptions.test.tsx | 20 +- .../src/__tests__/queryOptions.test-d.tsx | 42 +-- .../src/__tests__/ssr-hydration.test.tsx | 6 +- .../preact-query/src/__tests__/ssr.test.tsx | 12 +- .../src/__tests__/suspense.test.tsx | 16 +- .../src/__tests__/useInfiniteQuery.test-d.tsx | 20 +- .../src/__tests__/useInfiniteQuery.test.tsx | 56 +-- .../src/__tests__/useIsFetching.test.tsx | 16 +- .../src/__tests__/useMutation.test.tsx | 16 +- .../src/__tests__/useMutationState.test.tsx | 42 +-- .../usePrefetchInfiniteQuery.test-d.tsx | 16 +- .../usePrefetchInfiniteQuery.test.tsx | 8 +- .../src/__tests__/usePrefetchQuery.test-d.tsx | 14 +- .../src/__tests__/usePrefetchQuery.test.tsx | 18 +- .../src/__tests__/useQueries.test-d.tsx | 50 +-- .../src/__tests__/useQueries.test.tsx | 88 ++--- .../src/__tests__/useQuery.test-d.tsx | 26 +- .../src/__tests__/useQuery.test.tsx | 306 ++++++++-------- .../useSuspenseInfiniteQuery.test-d.tsx | 20 +- .../useSuspenseInfiniteQuery.test.tsx | 8 +- .../__tests__/useSuspenseQueries.test-d.tsx | 34 +- .../src/__tests__/useSuspenseQueries.test.tsx | 60 ++-- .../src/__tests__/useSuspenseQuery.test-d.tsx | 20 +- .../src/__tests__/useSuspenseQuery.test.tsx | 60 ++-- .../src/__tests__/index.test.ts | 28 +- .../src/__tests__/hydration.test.tsx | 116 +++--- .../__tests__/infiniteQueryBehavior.test.tsx | 22 +- .../infiniteQueryObserver.test-d.tsx | 80 ++--- .../__tests__/infiniteQueryObserver.test.tsx | 18 +- .../src/__tests__/mutation.test.tsx | 48 +-- .../src/__tests__/mutationCache.test.tsx | 18 +- .../src/__tests__/mutationObserver.test.tsx | 6 +- .../src/__tests__/queriesObserver.test-d.tsx | 10 +- .../src/__tests__/queriesObserver.test.tsx | 82 ++--- .../query-core/src/__tests__/query.test-d.tsx | 78 ++-- .../query-core/src/__tests__/query.test.tsx | 108 +++--- .../src/__tests__/queryCache.test-d.tsx | 14 +- .../src/__tests__/queryCache.test.tsx | 44 +-- .../src/__tests__/queryClient.test-d.tsx | 4 +- .../src/__tests__/queryClient.test.tsx | 336 +++++++++--------- .../src/__tests__/queryObserver.test-d.tsx | 194 +++++----- .../src/__tests__/queryObserver.test.tsx | 156 ++++---- .../src/__tests__/streamedQuery.test.tsx | 34 +- .../query-core/src/__tests__/utils.test.tsx | 10 +- .../src/__tests__/createKey.test.ts | 13 + .../src/__tests__/queryKey.test.ts | 13 - packages/query-test-utils/src/createKey.ts | 11 + packages/query-test-utils/src/index.ts | 2 +- packages/query-test-utils/src/queryKey.ts | 10 - .../PersistQueryClientProvider.test.tsx | 22 +- .../__tests__/QueryClientProvider.test.tsx | 10 +- .../QueryResetErrorBoundary.test.tsx | 28 +- .../__tests__/fine-grained-persister.test.tsx | 8 +- .../__tests__/infiniteQueryOptions.test-d.tsx | 30 +- .../__tests__/infiniteQueryOptions.test.tsx | 4 +- .../src/__tests__/mutationOptions.test-d.tsx | 24 +- .../src/__tests__/mutationOptions.test.tsx | 20 +- .../src/__tests__/queryOptions.test-d.tsx | 42 +-- .../src/__tests__/ssr-hydration.test.tsx | 8 +- .../react-query/src/__tests__/ssr.test.tsx | 18 +- .../src/__tests__/suspense.test.tsx | 16 +- .../src/__tests__/transition.test.tsx | 6 +- .../src/__tests__/useInfiniteQuery.test-d.tsx | 20 +- .../src/__tests__/useInfiniteQuery.test.tsx | 58 +-- .../src/__tests__/useIsFetching.test.tsx | 16 +- .../src/__tests__/useMutation.test.tsx | 16 +- .../src/__tests__/useMutationState.test.tsx | 42 +-- .../usePrefetchInfiniteQuery.test-d.tsx | 16 +- .../usePrefetchInfiniteQuery.test.tsx | 8 +- .../src/__tests__/usePrefetchQuery.test-d.tsx | 16 +- .../src/__tests__/usePrefetchQuery.test.tsx | 18 +- .../src/__tests__/useQueries.test-d.tsx | 70 ++-- .../src/__tests__/useQueries.test.tsx | 90 ++--- .../src/__tests__/useQuery.test-d.tsx | 26 +- .../src/__tests__/useQuery.test.tsx | 310 ++++++++-------- .../useSuspenseInfiniteQuery.test-d.tsx | 20 +- .../useSuspenseInfiniteQuery.test.tsx | 17 +- .../__tests__/useSuspenseQueries.test-d.tsx | 54 +-- .../src/__tests__/useSuspenseQueries.test.tsx | 62 ++-- .../src/__tests__/useSuspenseQuery.test-d.tsx | 20 +- .../src/__tests__/useSuspenseQuery.test.tsx | 60 ++-- .../PersistQueryClientProvider.test.tsx | 16 +- .../__tests__/QueryClientProvider.test.tsx | 10 +- .../__tests__/infiniteQueryOptions.test-d.tsx | 6 +- .../src/__tests__/mutationOptions.test-d.tsx | 24 +- .../src/__tests__/mutationOptions.test.tsx | 20 +- .../src/__tests__/queryOptions.test-d.tsx | 34 +- .../src/__tests__/suspense.test.tsx | 39 +- .../src/__tests__/transition.test.tsx | 4 +- .../src/__tests__/useInfiniteQuery.test-d.tsx | 24 +- .../src/__tests__/useInfiniteQuery.test.tsx | 60 ++-- .../src/__tests__/useIsFetching.test.tsx | 20 +- .../src/__tests__/useIsMutating.test.tsx | 18 +- .../src/__tests__/useMutation.test.tsx | 14 +- .../src/__tests__/useMutationState.test.tsx | 6 +- .../src/__tests__/useQueries.test-d.tsx | 64 ++-- .../src/__tests__/useQueries.test.tsx | 14 +- .../src/__tests__/useQuery.test-d.tsx | 22 +- .../src/__tests__/useQuery.test.tsx | 254 ++++++------- .../tests/createInfiniteQuery/Base.svelte | 4 +- .../createInfiniteQuery/InitialData.svelte | 4 +- .../tests/createInfiniteQuery/Select.svelte | 4 +- .../createInfiniteQuery.svelte.test.ts | 6 +- .../createInfiniteQuery.test-d.ts | 26 +- .../createMutation.svelte.test.ts | 10 +- .../tests/createQueries/IsRestoring.svelte | 6 +- .../createQueries.svelte.test.ts | 18 +- .../createQueries/createQueries.test-d.ts | 26 +- .../tests/createQuery/IsRestoring.svelte | 4 +- .../createQuery/createQuery.svelte.test.ts | 92 ++--- .../tests/createQuery/createQuery.test-d.ts | 24 +- .../tests/infiniteQueryOptions.test-d.ts | 12 +- .../mutationOptions.svelte.test.ts | 20 +- .../mutationOptions/mutationOptions.test-d.ts | 24 +- .../svelte-query/tests/queryOptions.test-d.ts | 34 +- .../tests/useIsFetching/Base.svelte | 4 +- .../tests/useIsMutating/Base.svelte | 4 +- .../useMutationState.svelte.test.ts | 20 +- .../__tests__/infiniteQueryOptions.test-d.ts | 18 +- .../__tests__/infiniteQueryOptions.test.ts | 4 +- .../src/__tests__/mutationOptions.test.ts | 4 +- .../src/__tests__/queryClient.test-d.ts | 8 +- .../src/__tests__/queryOptions.test-d.ts | 52 +-- .../src/__tests__/queryOptions.test.ts | 4 +- packages/vue-query/src/__tests__/ssr.test.ts | 4 +- .../src/__tests__/useInfiniteQuery.test-d.tsx | 18 +- .../src/__tests__/useInfiniteQuery.test.ts | 16 +- .../src/__tests__/useIsFetching.test.ts | 12 +- .../src/__tests__/useIsMutating.test.ts | 14 +- .../src/__tests__/useMutation.test.ts | 22 +- .../src/__tests__/useMutationState.test.ts | 8 +- .../usePrefetchInfiniteQuery.test-d.ts | 18 +- .../usePrefetchInfiniteQuery.test.ts | 12 +- .../src/__tests__/usePrefetchQuery.test-d.ts | 16 +- .../src/__tests__/usePrefetchQuery.test.ts | 12 +- .../src/__tests__/useQueries.test-d.ts | 28 +- .../src/__tests__/useQueries.test.ts | 58 +-- .../src/__tests__/useQuery.test-d.ts | 46 +-- .../vue-query/src/__tests__/useQuery.test.ts | 74 ++-- .../src/__tests__/vueQueryPlugin.test.ts | 8 +- 182 files changed, 3051 insertions(+), 3032 deletions(-) create mode 100644 packages/query-test-utils/src/__tests__/createKey.test.ts delete mode 100644 packages/query-test-utils/src/__tests__/queryKey.test.ts create mode 100644 packages/query-test-utils/src/createKey.ts delete mode 100644 packages/query-test-utils/src/queryKey.ts diff --git a/packages/angular-query-experimental/src/__tests__/infinite-query-options.test-d.ts b/packages/angular-query-experimental/src/__tests__/infinite-query-options.test-d.ts index 1aee84593b9..ec0acb9f2c6 100644 --- a/packages/angular-query-experimental/src/__tests__/infinite-query-options.test-d.ts +++ b/packages/angular-query-experimental/src/__tests__/infinite-query-options.test-d.ts @@ -1,5 +1,5 @@ import { assertType, describe, expectTypeOf, it } from 'vitest' -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { QueryClient, dataTagSymbol, skipToken } from '@tanstack/query-core' import { infiniteQueryOptions } from '../infinite-query-options' import { injectInfiniteQuery } from '../inject-infinite-query' @@ -21,7 +21,7 @@ export const exportedInfiniteQueryOptions = infiniteQueryOptions({ describe('infiniteQueryOptions', () => { it('should not allow excess properties', () => { - const key = queryKey() + const key = createKey() assertType( infiniteQueryOptions({ queryKey: key, @@ -35,7 +35,7 @@ describe('infiniteQueryOptions', () => { }) it('should infer types for callbacks', () => { - const key = queryKey() + const key = createKey() infiniteQueryOptions({ queryKey: key, queryFn: () => Promise.resolve('data'), @@ -49,7 +49,7 @@ describe('infiniteQueryOptions', () => { }) it('should work when passed to useInfiniteQuery', () => { - const key = queryKey() + const key = createKey() const options = infiniteQueryOptions({ queryKey: key, queryFn: () => Promise.resolve('string'), @@ -66,7 +66,7 @@ describe('infiniteQueryOptions', () => { }) it('should work when passed to fetchInfiniteQuery', async () => { - const key = queryKey() + const key = createKey() const options = infiniteQueryOptions({ queryKey: key, queryFn: () => Promise.resolve('string'), @@ -135,7 +135,7 @@ describe('infiniteQueryOptions', () => { }) it('should tag the queryKey with the result type of the QueryFn', () => { - const key = queryKey() + const key = createKey() const { queryKey: tagged } = infiniteQueryOptions({ queryKey: key, queryFn: () => Promise.resolve('string'), @@ -147,7 +147,7 @@ describe('infiniteQueryOptions', () => { }) it('should tag the queryKey even if no promise is returned', () => { - const key = queryKey() + const key = createKey() const { queryKey: tagged } = infiniteQueryOptions({ queryKey: key, queryFn: () => 'string', @@ -159,7 +159,7 @@ describe('infiniteQueryOptions', () => { }) it('should tag the queryKey with the result type of the QueryFn if select is used', () => { - const key = queryKey() + const key = createKey() const { queryKey: tagged } = infiniteQueryOptions({ queryKey: key, queryFn: () => Promise.resolve('string'), @@ -172,7 +172,7 @@ describe('infiniteQueryOptions', () => { }) it('should return the proper type when passed to getQueryData', () => { - const key = queryKey() + const key = createKey() const { queryKey: tagged } = infiniteQueryOptions({ queryKey: key, queryFn: () => Promise.resolve('string'), @@ -189,7 +189,7 @@ describe('infiniteQueryOptions', () => { }) it('should properly type when passed to setQueryData', () => { - const key = queryKey() + const key = createKey() const { queryKey: tagged } = infiniteQueryOptions({ queryKey: key, queryFn: () => Promise.resolve('string'), @@ -211,7 +211,7 @@ describe('infiniteQueryOptions', () => { }) it('should not be allowed to be passed to non-infinite query functions', () => { - const key = queryKey() + const key = createKey() const queryClient = new QueryClient() const options = infiniteQueryOptions({ queryKey: key, @@ -247,7 +247,7 @@ describe('infiniteQueryOptions', () => { }) it('should allow optional initialData function', () => { - const key = queryKey() + const key = createKey() const initialData: { example: boolean } | undefined = { example: true } const queryOptions = infiniteQueryOptions({ queryKey: key, @@ -266,7 +266,7 @@ describe('infiniteQueryOptions', () => { }) it('should allow optional initialData object', () => { - const key = queryKey() + const key = createKey() const initialData: { example: boolean } | undefined = { example: true } const queryOptions = infiniteQueryOptions({ queryKey: key, diff --git a/packages/angular-query-experimental/src/__tests__/infinite-query-options.test.ts b/packages/angular-query-experimental/src/__tests__/infinite-query-options.test.ts index 9459d96839f..b6795ad9cae 100644 --- a/packages/angular-query-experimental/src/__tests__/infinite-query-options.test.ts +++ b/packages/angular-query-experimental/src/__tests__/infinite-query-options.test.ts @@ -1,12 +1,12 @@ import { describe, expect, it } from 'vitest' -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { infiniteQueryOptions } from '../infinite-query-options' import type { CreateInfiniteQueryOptions } from '../types' describe('infiniteQueryOptions', () => { it('should return the object received as a parameter without any modification.', () => { - const key = queryKey() + const key = createKey() const object: CreateInfiniteQueryOptions = { queryKey: key, queryFn: () => Promise.resolve(5), diff --git a/packages/angular-query-experimental/src/__tests__/inject-infinite-query.test-d.ts b/packages/angular-query-experimental/src/__tests__/inject-infinite-query.test-d.ts index 6e880ea494c..1809aa6c714 100644 --- a/packages/angular-query-experimental/src/__tests__/inject-infinite-query.test-d.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-infinite-query.test-d.ts @@ -1,7 +1,7 @@ import { TestBed } from '@angular/core/testing' import { afterEach, beforeEach, describe, expectTypeOf, it, vi } from 'vitest' import { provideZonelessChangeDetection } from '@angular/core' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { QueryClient, injectInfiniteQuery, @@ -29,7 +29,7 @@ describe('injectInfiniteQuery', () => { }) it('should narrow type after isSuccess', () => { - const key = queryKey() + const key = createKey() const query = TestBed.runInInjectionContext(() => { return injectInfiniteQuery(() => ({ queryKey: key, @@ -47,7 +47,7 @@ describe('injectInfiniteQuery', () => { }) it('should work when queryFn is skipToken', () => { - const key = queryKey() + const key = createKey() const query = TestBed.runInInjectionContext(() => { return injectInfiniteQuery(() => ({ queryKey: key, diff --git a/packages/angular-query-experimental/src/__tests__/inject-infinite-query.test.ts b/packages/angular-query-experimental/src/__tests__/inject-infinite-query.test.ts index 62911935f73..afe0f508dc6 100644 --- a/packages/angular-query-experimental/src/__tests__/inject-infinite-query.test.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-infinite-query.test.ts @@ -7,7 +7,7 @@ import { signal, } from '@angular/core' import { render } from '@testing-library/angular' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { QueryClient, injectInfiniteQuery, @@ -34,7 +34,7 @@ describe('injectInfiniteQuery', () => { }) it('should properly execute infinite query', async () => { - const key = queryKey() + const key = createKey() @Component({ template: ` @@ -71,7 +71,7 @@ describe('injectInfiniteQuery', () => { }) it('should reject and update signal', async () => { - const key = queryKey() + const key = createKey() @Component({ template: ` @@ -107,7 +107,7 @@ describe('injectInfiniteQuery', () => { }) it('should keep initialData visible alongside the error when a refetch fails', async () => { - const key = queryKey() + const key = createKey() @Component({ template: ` @@ -139,7 +139,7 @@ describe('injectInfiniteQuery', () => { describe('skipToken', () => { it('should not fetch when queryFn is skipToken, and fetch once it is replaced', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn< (context: { pageParam: number }) => Promise >(({ pageParam }: { pageParam: number }) => @@ -189,7 +189,7 @@ describe('injectInfiniteQuery', () => { describe('injection context', () => { it('should throw NG0203 with descriptive error outside injection context', () => { - const key = queryKey() + const key = createKey() expect(() => { injectInfiniteQuery(() => ({ queryKey: key, @@ -202,7 +202,7 @@ describe('injectInfiniteQuery', () => { }) it('should be usable outside injection context when passing an injector', () => { - const key = queryKey() + const key = createKey() const query = injectInfiniteQuery( () => ({ queryKey: key, diff --git a/packages/angular-query-experimental/src/__tests__/inject-is-fetching.test.ts b/packages/angular-query-experimental/src/__tests__/inject-is-fetching.test.ts index b18e388ec4e..63d4798fa30 100644 --- a/packages/angular-query-experimental/src/__tests__/inject-is-fetching.test.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-is-fetching.test.ts @@ -6,7 +6,7 @@ import { provideZonelessChangeDetection, } from '@angular/core' import { render } from '@testing-library/angular' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { QueryClient, injectIsFetching, @@ -34,7 +34,7 @@ describe('injectIsFetching', () => { }) it('should return the number of fetching queries', async () => { - const key = queryKey() + const key = createKey() @Component({ template: `
fetching: {{ isFetching() }}
`, @@ -59,8 +59,8 @@ describe('injectIsFetching', () => { }) it('should be able to filter by queryKey', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() @Component({ template: `
fetching: {{ isFetching() }}
`, diff --git a/packages/angular-query-experimental/src/__tests__/inject-is-mutating.test.ts b/packages/angular-query-experimental/src/__tests__/inject-is-mutating.test.ts index 56afdc46a52..1988c971a56 100644 --- a/packages/angular-query-experimental/src/__tests__/inject-is-mutating.test.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-is-mutating.test.ts @@ -6,7 +6,7 @@ import { provideZonelessChangeDetection, } from '@angular/core' import { render } from '@testing-library/angular' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { QueryClient, injectIsMutating, @@ -34,7 +34,7 @@ describe('injectIsMutating', () => { }) it('should properly return isMutating state', async () => { - const key = queryKey() + const key = createKey() @Component({ template: `
mutating: {{ isMutating() }}
`, @@ -61,8 +61,8 @@ describe('injectIsMutating', () => { }) it('should be able to filter by mutationKey', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() @Component({ template: `
mutating: {{ isMutating() }}
`, diff --git a/packages/angular-query-experimental/src/__tests__/inject-mutation-state.test.ts b/packages/angular-query-experimental/src/__tests__/inject-mutation-state.test.ts index 9be3e6e1827..6e42c2d8891 100644 --- a/packages/angular-query-experimental/src/__tests__/inject-mutation-state.test.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-mutation-state.test.ts @@ -8,7 +8,7 @@ import { import { TestBed } from '@angular/core/testing' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { By } from '@angular/platform-browser' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { QueryClient, injectMutation, @@ -37,7 +37,7 @@ describe('injectMutationState', () => { describe('injectMutationState', () => { it('should return variables after calling mutate 1', () => { - const mutationKey = queryKey() + const mutationKey = createKey() const variables = 'foo123' const mutation = TestBed.runInInjectionContext(() => { @@ -60,8 +60,8 @@ describe('injectMutationState', () => { }) it('should update injectMutationState when reactive options change', () => { - const mutationKey1 = queryKey() - const mutationKey2 = queryKey() + const mutationKey1 = createKey() + const mutationKey2 = createKey() const variables1 = 'foo123' const variables2 = 'bar234' @@ -98,7 +98,7 @@ describe('injectMutationState', () => { it('should return variables after calling mutate 2', () => { queryClient.clear() - const mutationKey = queryKey() + const mutationKey = createKey() const variables = 'bar234' const mutation = TestBed.runInInjectionContext(() => { diff --git a/packages/angular-query-experimental/src/__tests__/inject-mutation.test.ts b/packages/angular-query-experimental/src/__tests__/inject-mutation.test.ts index f48c089def5..3b587150064 100644 --- a/packages/angular-query-experimental/src/__tests__/inject-mutation.test.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-mutation.test.ts @@ -10,7 +10,7 @@ import { TestBed } from '@angular/core/testing' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { By } from '@angular/platform-browser' import { render } from '@testing-library/angular' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { noop } from '@tanstack/query-core' import { QueryClient, injectMutation, provideTanStackQuery } from '..' import { expectSignals, setFixtureSignalInputs } from './test-utils' @@ -148,8 +148,8 @@ describe('injectMutation', () => { const mutationCache = queryClient.getMutationCache() // Signal will be updated before the mutation is called // this test confirms that the mutation uses the updated value - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const mutationKey = signal(key1) const mutation = TestBed.runInInjectionContext(() => { return injectMutation(() => ({ @@ -546,7 +546,7 @@ describe('injectMutation', () => { }) it('should give mutationFn the same QueryClient instance via context', async () => { - const key = queryKey() + const key = createKey() queryClient.setQueryData(key, 'tag-from-this-client') @Component({ @@ -597,7 +597,7 @@ describe('injectMutation', () => { }) it('should let onSuccess invalidate queries via context.client without an injected QueryClient', async () => { - const key = queryKey() + const key = createKey() queryClient.setQueryData(key, 'data') const mutation = TestBed.runInInjectionContext(() => { @@ -731,7 +731,7 @@ describe('injectMutation', () => { describe('throwOnError', () => { it('should evaluate throwOnError when mutation is expected to throw', async () => { - const key = queryKey() + const key = createKey() const err = new Error('Expected mock error. All is well!') const throwOnError = vi.fn<(error: Error) => boolean>() const { mutate } = TestBed.runInInjectionContext(() => { @@ -753,7 +753,7 @@ describe('injectMutation', () => { }) it('should throw when throwOnError is true and mutate is used', async () => { - const key = queryKey() + const key = createKey() const { mutate } = TestBed.runInInjectionContext(() => { return injectMutation(() => ({ mutationKey: key, @@ -776,7 +776,7 @@ describe('injectMutation', () => { }) it('should throw when throwOnError is true', async () => { - const key = queryKey() + const key = createKey() const err = new Error('Expected mock error. All is well!') const { mutateAsync } = TestBed.runInInjectionContext(() => { return injectMutation(() => ({ @@ -792,7 +792,7 @@ describe('injectMutation', () => { }) it('should throw when throwOnError function returns true', async () => { - const key = queryKey() + const key = createKey() const err = new Error('Expected mock error. All is well!') const { mutateAsync } = TestBed.runInInjectionContext(() => { return injectMutation(() => ({ @@ -808,7 +808,7 @@ describe('injectMutation', () => { }) it('should resolve mutateAsync with the value returned from mutationFn', async () => { - const key = queryKey() + const key = createKey() const { mutateAsync } = TestBed.runInInjectionContext(() => { return injectMutation(() => ({ mutationKey: key, @@ -823,7 +823,7 @@ describe('injectMutation', () => { describe('injection context', () => { it('should throw NG0203 with descriptive error outside injection context', () => { - const key = queryKey() + const key = createKey() expect(() => { injectMutation(() => ({ mutationKey: key, @@ -833,7 +833,7 @@ describe('injectMutation', () => { }) it('should be usable outside injection context when passing an injector', () => { - const key = queryKey() + const key = createKey() expect(() => { injectMutation( () => ({ @@ -852,7 +852,7 @@ describe('injectMutation', () => { let mutationStarted = false let mutationCompleted = false - const key = queryKey() + const key = createKey() const mutation = TestBed.runInInjectionContext(() => injectMutation(() => ({ mutationKey: key, @@ -927,7 +927,7 @@ describe('injectMutation', () => { const app = TestBed.inject(ApplicationRef) let callCount = 0 - const key = queryKey() + const key = createKey() const mutation1 = TestBed.runInInjectionContext(() => injectMutation(() => ({ @@ -970,7 +970,7 @@ describe('injectMutation', () => { it('should handle synchronous mutation with optimistic updates', async () => { const app = TestBed.inject(ApplicationRef) - const testQueryKey = queryKey() + const testQueryKey = createKey() let onMutateCalled = false let onSuccessCalled = false @@ -1014,7 +1014,7 @@ describe('injectMutation', () => { it('should handle synchronous mutation cancellation', async () => { const app = TestBed.inject(ApplicationRef) - const key = queryKey() + const key = createKey() const mutation = TestBed.runInInjectionContext(() => injectMutation(() => ({ mutationKey: key, @@ -1042,7 +1042,7 @@ describe('injectMutation', () => { describe('optimistic updates', () => { it('should update the cache in onMutate and roll back via onMutateResult in onError', async () => { - const key = queryKey() + const key = createKey() queryClient.setQueryData>(key, ['Todo 1']) @Component({ @@ -1083,7 +1083,7 @@ describe('injectMutation', () => { }) it('should keep the optimistic update in place when the mutation succeeds', async () => { - const key = queryKey() + const key = createKey() queryClient.setQueryData>(key, ['Todo 1']) @Component({ diff --git a/packages/angular-query-experimental/src/__tests__/inject-queries.test-d.ts b/packages/angular-query-experimental/src/__tests__/inject-queries.test-d.ts index 433ff7d2cce..554ad018655 100644 --- a/packages/angular-query-experimental/src/__tests__/inject-queries.test-d.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-queries.test-d.ts @@ -1,5 +1,5 @@ import { describe, expectTypeOf, it } from 'vitest' -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { skipToken } from '..' import { injectQueries } from '../inject-queries' import { queryOptions } from '../query-options' @@ -9,9 +9,9 @@ import type { Signal } from '@angular/core' describe('injectQueries', () => { describe('config object overload', () => { it('should always define TData when initialData is provided as an object', () => { - const key1 = queryKey() - const key2 = queryKey() - const key3 = queryKey() + const key1 = createKey() + const key2 = createKey() + const key3 = createKey() const query1 = { queryKey: key1, @@ -50,7 +50,7 @@ describe('injectQueries', () => { }) it('should define TData when passed through queryOptions', () => { - const key = queryKey() + const key = createKey() const options = queryOptions({ queryKey: key, queryFn: () => { @@ -70,8 +70,8 @@ describe('injectQueries', () => { }) it('should be possible to define a different TData than TQueryFnData using select with queryOptions spread into injectQuery', () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const query1 = queryOptions({ queryKey: key1, @@ -94,7 +94,7 @@ describe('injectQueries', () => { }) it('should have undefined in the TData union when initialData is provided as a function which can return undefined', () => { - const key = queryKey() + const key = createKey() const queryResults = injectQueries(() => ({ queries: [ { @@ -117,7 +117,7 @@ describe('injectQueries', () => { describe('custom injectable', () => { it('should allow custom hooks using UseQueryOptions', () => { type Data = string - const key = queryKey() + const key = createKey() const injectCustomQueries = ( options?: OmitKeyof, 'queryKey' | 'queryFn'>, @@ -141,7 +141,7 @@ describe('injectQueries', () => { }) it('should have correct TData type when conditional skipToken is passed', () => { - const key = queryKey() + const key = createKey() const queryResults = injectQueries(() => ({ queries: [ { @@ -160,8 +160,8 @@ describe('injectQueries', () => { }) it('should return correct data for dynamic queries with mixed result types', () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const Queries1 = { get: () => diff --git a/packages/angular-query-experimental/src/__tests__/inject-queries.test.ts b/packages/angular-query-experimental/src/__tests__/inject-queries.test.ts index 6aaa2777868..843d2cf96ee 100644 --- a/packages/angular-query-experimental/src/__tests__/inject-queries.test.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-queries.test.ts @@ -7,7 +7,7 @@ import { } from '@angular/core' import { TestBed } from '@angular/core/testing' import { render } from '@testing-library/angular' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { QueryClient, provideIsRestoring, provideTanStackQuery } from '..' import { injectQueries } from '../inject-queries' @@ -30,8 +30,8 @@ describe('injectQueries', () => { }) it('should return the correct states', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const results: Array>> = [] @Component({ @@ -79,8 +79,8 @@ describe('injectQueries', () => { }) it('should return the combined result when combine is provided', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const results: Array> = [] @Component({ @@ -134,8 +134,8 @@ describe('injectQueries', () => { }) it('should reflect error state when one of the queries rejects', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() @Component({ template: ` @@ -178,8 +178,8 @@ describe('injectQueries', () => { describe('isRestoring', () => { it('should not fetch for the duration of the restoring period when isRestoring is true', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const queryFn1 = vi.fn<() => Promise>(() => sleep(10).then(() => 1), ) diff --git a/packages/angular-query-experimental/src/__tests__/inject-query.test-d.ts b/packages/angular-query-experimental/src/__tests__/inject-query.test-d.ts index 9627483e18c..f7017d41193 100644 --- a/packages/angular-query-experimental/src/__tests__/inject-query.test-d.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-query.test-d.ts @@ -1,12 +1,12 @@ import { describe, expectTypeOf, it } from 'vitest' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { injectQuery, queryOptions } from '..' import type { Signal } from '@angular/core' import type { CreateQueryOptions, OmitKeyof, QueryFunction } from '..' describe('injectQuery', () => { it('should return the correct types', () => { - const key = queryKey() + const key = createKey() // unspecified query function should default to unknown const noQueryFn = injectQuery(() => ({ queryKey: key, @@ -170,7 +170,7 @@ describe('injectQuery', () => { describe('initialData', () => { describe('Config object overload', () => { it('should always define TData when initialData is provided as an object', () => { - const key = queryKey() + const key = createKey() const { data } = injectQuery(() => ({ queryKey: key, queryFn: () => ({ wow: true }), @@ -181,7 +181,7 @@ describe('injectQuery', () => { }) it('should define TData when passed through queryOptions', () => { - const key = queryKey() + const key = createKey() const options = () => queryOptions({ queryKey: key, @@ -200,7 +200,7 @@ describe('injectQuery', () => { }) it('should be possible to define a different TData than TQueryFnData using select with queryOptions spread into useQuery', () => { - const key = queryKey() + const key = createKey() const options = queryOptions({ queryKey: key, queryFn: () => Promise.resolve(1), @@ -215,7 +215,7 @@ describe('injectQuery', () => { }) it('should always define TData when initialData is provided as a function which ALWAYS returns the data', () => { - const key = queryKey() + const key = createKey() const { data } = injectQuery(() => ({ queryKey: key, queryFn: () => { @@ -232,7 +232,7 @@ describe('injectQuery', () => { }) it('should have undefined in the TData union when initialData is NOT provided', () => { - const key = queryKey() + const key = createKey() const { data } = injectQuery(() => ({ queryKey: key, queryFn: () => { @@ -246,7 +246,7 @@ describe('injectQuery', () => { }) it('should have undefined in the TData union when initialData is provided as a function which can return undefined', () => { - const key = queryKey() + const key = createKey() const { data } = injectQuery(() => ({ queryKey: key, queryFn: () => { @@ -261,7 +261,7 @@ describe('injectQuery', () => { }) it('should narrow TData after an isSuccess check when initialData is provided as a function which can return undefined', () => { - const key = queryKey() + const key = createKey() const query = injectQuery(() => ({ queryKey: key, queryFn: () => { @@ -280,7 +280,7 @@ describe('injectQuery', () => { describe('structuralSharing', () => { it('should be able to use structuralSharing with unknown types', () => { - const key = queryKey() + const key = createKey() // https://github.com/TanStack/query/issues/6525#issuecomment-1938411343 injectQuery(() => ({ queryKey: key, @@ -297,7 +297,7 @@ describe('injectQuery', () => { describe('Discriminated union return type', () => { it('should have possibly undefined data by default', () => { - const key = queryKey() + const key = createKey() const query = injectQuery(() => ({ queryKey: key, queryFn: () => sleep(0).then(() => 'Some data'), @@ -307,7 +307,7 @@ describe('injectQuery', () => { }) it('should have defined data when query is success', () => { - const key = queryKey() + const key = createKey() const query = injectQuery(() => ({ queryKey: key, queryFn: () => sleep(0).then(() => 'Some data'), @@ -319,7 +319,7 @@ describe('injectQuery', () => { }) it('should have null error when query is success', () => { - const key = queryKey() + const key = createKey() const query = injectQuery(() => ({ queryKey: key, queryFn: () => sleep(0).then(() => 'Some data'), @@ -331,7 +331,7 @@ describe('injectQuery', () => { }) it('should have undefined data when query is pending', () => { - const key = queryKey() + const key = createKey() const query = injectQuery(() => ({ queryKey: key, queryFn: () => sleep(0).then(() => 'Some data'), @@ -343,7 +343,7 @@ describe('injectQuery', () => { }) it('should have defined error when query is error', () => { - const key = queryKey() + const key = createKey() const query = injectQuery(() => ({ queryKey: key, queryFn: () => sleep(0).then(() => 'Some data'), diff --git a/packages/angular-query-experimental/src/__tests__/inject-query.test.ts b/packages/angular-query-experimental/src/__tests__/inject-query.test.ts index 5a836290aee..9393c42b47d 100644 --- a/packages/angular-query-experimental/src/__tests__/inject-query.test.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-query.test.ts @@ -15,7 +15,7 @@ import { } from '@angular/common/http/testing' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { render } from '@testing-library/angular' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { lastValueFrom } from 'rxjs' import { QueryCache, @@ -48,7 +48,7 @@ describe('injectQuery', () => { }) it('should return pending status initially', () => { - const key = queryKey() + const key = createKey() const query = TestBed.runInInjectionContext(() => { return injectQuery(() => ({ queryKey: key, @@ -64,7 +64,7 @@ describe('injectQuery', () => { }) it('should resolve to success and update signal: injectQuery()', async () => { - const key = queryKey() + const key = createKey() @Component({ template: ` @@ -96,7 +96,7 @@ describe('injectQuery', () => { }) it('should reject and update signal', async () => { - const key = queryKey() + const key = createKey() @Component({ template: ` @@ -134,7 +134,7 @@ describe('injectQuery', () => { }) it('should be able to select a part of the data with select', async () => { - const key = queryKey() + const key = createKey() @Component({ template: `
data: {{ query.data() ?? 'none' }}
`, @@ -156,7 +156,7 @@ describe('injectQuery', () => { }) it('should show placeholderData until queryFn resolves and then expose real data', async () => { - const key = queryKey() + const key = createKey() @Component({ template: ` @@ -186,8 +186,8 @@ describe('injectQuery', () => { }) it('should update query on options contained signal change', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const key = signal(key1) const queryFn = vi.fn<() => Promise>(() => sleep(10).then(() => 'Some data'), @@ -218,7 +218,7 @@ describe('injectQuery', () => { }) it('should only run query once enabled signal is set to true', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => sleep(10).then(() => 'Some data'), ) @@ -242,7 +242,7 @@ describe('injectQuery', () => { }) it('should not fetch while the enabled signal is false, and fetch again once it is truthy', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => sleep(10).then(() => 'Some data'), ) @@ -271,8 +271,8 @@ describe('injectQuery', () => { }) it('should properly execute dependent queries', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const query1 = TestBed.runInInjectionContext(() => { return injectQuery(() => ({ @@ -311,7 +311,7 @@ describe('injectQuery', () => { }) it('should use the current value for the queryKey when refetch is called', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => sleep(10).then(() => 'Some data'), ) @@ -352,7 +352,7 @@ describe('injectQuery', () => { }) it('should keep initialData visible alongside the error when a refetch fails', async () => { - const key = queryKey() + const key = createKey() @Component({ template: ` @@ -382,7 +382,7 @@ describe('injectQuery', () => { describe('throwOnError', () => { it('should evaluate throwOnError when query is expected to throw', async () => { - const key = queryKey() + const key = createKey() const throwOnError = vi.fn<(error: Error, query: Query) => boolean>() TestBed.runInInjectionContext(() => { return injectQuery(() => ({ @@ -405,7 +405,7 @@ describe('injectQuery', () => { }) it('should throw when throwOnError is true', async () => { - const key = queryKey() + const key = createKey() TestBed.runInInjectionContext(() => { return injectQuery(() => ({ queryKey: key, @@ -419,7 +419,7 @@ describe('injectQuery', () => { }) it('should throw when throwOnError function returns true', async () => { - const key = queryKey() + const key = createKey() TestBed.runInInjectionContext(() => { return injectQuery(() => ({ queryKey: key, @@ -461,7 +461,7 @@ describe('injectQuery', () => { describe('isRestoring', () => { it('should not fetch for the duration of the restoring period when isRestoring is true', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => sleep(10).then(() => 'data'), ) @@ -492,7 +492,7 @@ describe('injectQuery', () => { describe('injection context', () => { it('should throw NG0203 with descriptive error outside injection context', () => { - const key = queryKey() + const key = createKey() expect(() => { injectQuery(() => ({ queryKey: key, @@ -502,7 +502,7 @@ describe('injectQuery', () => { }) it('should be usable outside injection context when passing an injector', () => { - const key = queryKey() + const key = createKey() const query = injectQuery( () => ({ queryKey: key, @@ -517,7 +517,7 @@ describe('injectQuery', () => { }) it('should complete queries before whenStable() resolves', async () => { - const key = queryKey() + const key = createKey() const app = TestBed.inject(ApplicationRef) const query = TestBed.runInInjectionContext(() => @@ -547,7 +547,7 @@ describe('injectQuery', () => { const httpTestingController = TestBed.inject(HttpTestingController) // Create a query using HttpClient - const key = queryKey() + const key = createKey() const query = TestBed.runInInjectionContext(() => injectQuery(() => ({ queryKey: key, @@ -581,7 +581,7 @@ describe('injectQuery', () => { const app = TestBed.inject(ApplicationRef) let callCount = 0 - const key = queryKey() + const key = createKey() const query = TestBed.runInInjectionContext(() => injectQuery(() => ({ queryKey: key, @@ -616,7 +616,7 @@ describe('injectQuery', () => { const enabledSignal = signal(false) let callCount = 0 - const key = queryKey() + const key = createKey() const query = TestBed.runInInjectionContext(() => injectQuery(() => ({ queryKey: key, @@ -646,7 +646,7 @@ describe('injectQuery', () => { it('should handle query invalidation with synchronous data', async () => { const app = TestBed.inject(ApplicationRef) - const testKey = queryKey() + const testKey = createKey() let callCount = 0 const query = TestBed.runInInjectionContext(() => diff --git a/packages/angular-query-experimental/src/__tests__/mutation-options.test-d.ts b/packages/angular-query-experimental/src/__tests__/mutation-options.test-d.ts index 9df834a6b56..612f109b828 100644 --- a/packages/angular-query-experimental/src/__tests__/mutation-options.test-d.ts +++ b/packages/angular-query-experimental/src/__tests__/mutation-options.test-d.ts @@ -1,5 +1,5 @@ import { assertType, describe, expectTypeOf, it } from 'vitest' -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { QueryClient } from '@tanstack/query-core' import { injectIsMutating, @@ -17,7 +17,7 @@ import type { CreateMutationOptions, CreateMutationResult } from '../types' describe('mutationOptions', () => { it('should not allow excess properties', () => { - const key = queryKey() + const key = createKey() mutationOptions({ mutationFn: () => Promise.resolve(5), // @ts-expect-error this is a good error, because onMutates does not exist! @@ -30,7 +30,7 @@ describe('mutationOptions', () => { }) it('should infer types for callbacks', () => { - const key = queryKey() + const key = createKey() mutationOptions({ mutationFn: () => Promise.resolve(5), mutationKey: key, @@ -41,7 +41,7 @@ describe('mutationOptions', () => { }) it('should infer types for onError callback', () => { - const key = queryKey() + const key = createKey() mutationOptions({ mutationFn: () => { throw new Error('fail') @@ -54,7 +54,7 @@ describe('mutationOptions', () => { }) it('should infer types for variables', () => { - const key = queryKey() + const key = createKey() mutationOptions({ mutationFn: (vars) => { expectTypeOf(vars).toEqualTypeOf<{ id: string }>() @@ -65,7 +65,7 @@ describe('mutationOptions', () => { }) it('should infer result type correctly', () => { - const key = queryKey() + const key = createKey() mutationOptions({ mutationFn: () => Promise.resolve(5), mutationKey: key, @@ -79,7 +79,7 @@ describe('mutationOptions', () => { }) it('should infer context type correctly', () => { - const key = queryKey() + const key = createKey() mutationOptions({ mutationFn: (_variables, context) => { expectTypeOf(context).toEqualTypeOf() @@ -120,7 +120,7 @@ describe('mutationOptions', () => { }) it('should infer all types when not explicitly provided', () => { - const key = queryKey() + const key = createKey() expectTypeOf( mutationOptions({ mutationFn: (id: string) => Promise.resolve(id.length), @@ -148,7 +148,7 @@ describe('mutationOptions', () => { }) it('should infer types when used with injectMutation', () => { - const key = queryKey() + const key = createKey() const mutation = injectMutation(() => mutationOptions({ mutationKey: key, @@ -175,7 +175,7 @@ describe('mutationOptions', () => { }) it('should infer types when used with injectIsMutating', () => { - const key = queryKey() + const key = createKey() const isMutating = injectIsMutating( mutationOptions({ mutationKey: key, @@ -193,7 +193,7 @@ describe('mutationOptions', () => { }) it('should infer types when used with queryClient.isMutating', () => { - const key = queryKey() + const key = createKey() const queryClient = new QueryClient() const isMutating = queryClient.isMutating( @@ -213,7 +213,7 @@ describe('mutationOptions', () => { }) it('should infer types when used with injectMutationState', () => { - const key = queryKey() + const key = createKey() const mutationState = injectMutationState(() => ({ filters: mutationOptions({ mutationKey: key, diff --git a/packages/angular-query-experimental/src/__tests__/mutation-options.test.ts b/packages/angular-query-experimental/src/__tests__/mutation-options.test.ts index 5a9b38e22af..efebbc12097 100644 --- a/packages/angular-query-experimental/src/__tests__/mutation-options.test.ts +++ b/packages/angular-query-experimental/src/__tests__/mutation-options.test.ts @@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { provideZonelessChangeDetection } from '@angular/core' import { TestBed } from '@angular/core/testing' import { QueryClient } from '@tanstack/query-core' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { injectIsMutating, injectMutation, @@ -31,7 +31,7 @@ describe('mutationOptions', () => { }) it('should return the object received as a parameter without any modification (with mutationKey in mutationOptions)', () => { - const key = queryKey() + const key = createKey() const object: CreateMutationOptions = { mutationKey: key, mutationFn: () => sleep(10).then(() => 5), @@ -49,7 +49,7 @@ describe('mutationOptions', () => { }) it('should return the number of fetching mutations when used with injectIsMutating (with mutationKey in mutationOptions)', async () => { - const key = queryKey() + const key = createKey() const mutationOpts = mutationOptions({ mutationKey: key, mutationFn: () => sleep(50).then(() => 'data'), @@ -91,7 +91,7 @@ describe('mutationOptions', () => { }) it('should return the number of fetching mutations when used with injectIsMutating', async () => { - const key = queryKey() + const key = createKey() const mutationOpts1 = mutationOptions({ mutationKey: key, mutationFn: () => sleep(50).then(() => 'data1'), @@ -120,7 +120,7 @@ describe('mutationOptions', () => { }) it('should return the number of fetching mutations when used with injectIsMutating (filter mutationOpts1.mutationKey)', async () => { - const key = queryKey() + const key = createKey() const mutationOpts1 = mutationOptions({ mutationKey: key, mutationFn: () => sleep(50).then(() => 'data1'), @@ -149,7 +149,7 @@ describe('mutationOptions', () => { }) it('should return the number of fetching mutations when used with queryClient.isMutating (with mutationKey in mutationOptions)', async () => { - const key = queryKey() + const key = createKey() const mutationOpts = mutationOptions({ mutationKey: key, mutationFn: () => sleep(500).then(() => 'data'), @@ -185,7 +185,7 @@ describe('mutationOptions', () => { }) it('should return the number of fetching mutations when used with queryClient.isMutating', async () => { - const key = queryKey() + const key = createKey() const mutationOpts1 = mutationOptions({ mutationKey: key, mutationFn: () => sleep(500).then(() => 'data1'), @@ -209,7 +209,7 @@ describe('mutationOptions', () => { }) it('should return the number of fetching mutations when used with queryClient.isMutating (filter mutationOpts1.mutationKey)', async () => { - const key = queryKey() + const key = createKey() const mutationOpts1 = mutationOptions({ mutationKey: key, mutationFn: () => sleep(500).then(() => 'data1'), @@ -239,7 +239,7 @@ describe('mutationOptions', () => { }) it('should return the number of fetching mutations when used with injectMutationState (with mutationKey in mutationOptions)', async () => { - const key = queryKey() + const key = createKey() const mutationOpts = mutationOptions({ mutationKey: key, mutationFn: () => sleep(10).then(() => 'data'), @@ -281,7 +281,7 @@ describe('mutationOptions', () => { }) it('should return the number of fetching mutations when used with injectMutationState', async () => { - const key = queryKey() + const key = createKey() const mutationOpts1 = mutationOptions({ mutationKey: key, mutationFn: () => sleep(10).then(() => 'data1'), @@ -311,7 +311,7 @@ describe('mutationOptions', () => { }) it('should return the number of fetching mutations when used with injectMutationState (filter mutationOpts1.mutationKey)', async () => { - const key = queryKey() + const key = createKey() const mutationOpts1 = mutationOptions({ mutationKey: key, mutationFn: () => sleep(10).then(() => 'data1'), diff --git a/packages/angular-query-experimental/src/__tests__/pending-tasks.test.ts b/packages/angular-query-experimental/src/__tests__/pending-tasks.test.ts index 44e07df4c6b..8e6e6c0a15d 100644 --- a/packages/angular-query-experimental/src/__tests__/pending-tasks.test.ts +++ b/packages/angular-query-experimental/src/__tests__/pending-tasks.test.ts @@ -10,7 +10,7 @@ import { provideHttpClientTesting, } from '@angular/common/http/testing' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { lastValueFrom } from 'rxjs' import { QueryClient, @@ -55,7 +55,7 @@ describe('PendingTasks Integration', () => { it('should handle synchronous queryFn with whenStable()', async () => { const app = TestBed.inject(ApplicationRef) - const key = queryKey() + const key = createKey() const query = TestBed.runInInjectionContext(() => injectQuery(() => ({ queryKey: key, @@ -81,7 +81,7 @@ describe('PendingTasks Integration', () => { it('should handle synchronous error with whenStable()', async () => { const app = TestBed.inject(ApplicationRef) - const key = queryKey() + const key = createKey() const query = TestBed.runInInjectionContext(() => injectQuery(() => ({ queryKey: key, @@ -152,7 +152,7 @@ describe('PendingTasks Integration', () => { describe('Race Conditions', () => { it('should handle query that completes during initial subscription', async () => { - const key = queryKey() + const key = createKey() const app = TestBed.inject(ApplicationRef) let resolveQuery: (value: string) => void @@ -182,7 +182,7 @@ describe('PendingTasks Integration', () => { const app = TestBed.inject(ApplicationRef) let callCount = 0 - const key = queryKey() + const key = createKey() const query = TestBed.runInInjectionContext(() => injectQuery(() => ({ queryKey: key, @@ -210,7 +210,7 @@ describe('PendingTasks Integration', () => { const app = TestBed.inject(ApplicationRef) let attempt = 0 - const key = queryKey() + const key = createKey() const query = TestBed.runInInjectionContext(() => injectQuery(() => ({ queryKey: key, @@ -320,9 +320,9 @@ describe('PendingTasks Integration', () => { describe('Concurrent Operations', () => { it('should handle multiple queries running simultaneously', async () => { - const key1 = queryKey() - const key2 = queryKey() - const key3 = queryKey() + const key1 = createKey() + const key2 = createKey() + const key3 = createKey() const app = TestBed.inject(ApplicationRef) const query1 = TestBed.runInInjectionContext(() => @@ -412,7 +412,7 @@ describe('PendingTasks Integration', () => { it('should handle mixed queries and mutations', async () => { const app = TestBed.inject(ApplicationRef) - const key = queryKey() + const key = createKey() const query = TestBed.runInInjectionContext(() => injectQuery(() => ({ queryKey: key, @@ -454,8 +454,8 @@ describe('PendingTasks Integration', () => { const httpClient = TestBed.inject(HttpClient) const httpTestingController = TestBed.inject(HttpTestingController) - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const query1 = TestBed.runInInjectionContext(() => injectQuery(() => ({ @@ -498,7 +498,7 @@ describe('PendingTasks Integration', () => { const httpClient = TestBed.inject(HttpClient) const httpTestingController = TestBed.inject(HttpTestingController) - const key = queryKey() + const key = createKey() const query = TestBed.runInInjectionContext(() => injectQuery(() => ({ queryKey: key, @@ -527,7 +527,7 @@ describe('PendingTasks Integration', () => { describe('Edge Cases', () => { it('should handle query cancellation mid-flight', async () => { - const key = queryKey() + const key = createKey() const app = TestBed.inject(ApplicationRef) const query = TestBed.runInInjectionContext(() => @@ -559,7 +559,7 @@ describe('PendingTasks Integration', () => { const app = TestBed.inject(ApplicationRef) let attemptCount = 0 - const key = queryKey() + const key = createKey() const query = TestBed.runInInjectionContext(() => injectQuery(() => ({ queryKey: key, @@ -585,7 +585,7 @@ describe('PendingTasks Integration', () => { it('should handle mutation with optimistic updates', async () => { const app = TestBed.inject(ApplicationRef) - const testQueryKey = queryKey() + const testQueryKey = createKey() queryClient.setQueryData(testQueryKey, 'initial-data') diff --git a/packages/angular-query-experimental/src/__tests__/query-options.test-d.ts b/packages/angular-query-experimental/src/__tests__/query-options.test-d.ts index aaf4a75de32..d313b718221 100644 --- a/packages/angular-query-experimental/src/__tests__/query-options.test-d.ts +++ b/packages/angular-query-experimental/src/__tests__/query-options.test-d.ts @@ -1,5 +1,5 @@ import { assertType, describe, expectTypeOf, it } from 'vitest' -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { QueryClient, dataTagSymbol, @@ -23,7 +23,7 @@ describe('queryOptions', () => { }) it('should infer types for callbacks', () => { - const key = queryKey() + const key = createKey() queryOptions({ queryKey: key, queryFn: () => Promise.resolve(5), @@ -35,7 +35,7 @@ describe('queryOptions', () => { }) it('should allow undefined response in initialData', () => { - const key = queryKey() + const key = createKey() const options = (id: string | null) => queryOptions({ queryKey: [...key, id], @@ -60,7 +60,7 @@ describe('queryOptions', () => { it('should allow optional initialData object', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('something string'), initialData: Math.random() > 0.5 ? 'initial string' : undefined, }) @@ -71,7 +71,7 @@ describe('queryOptions', () => { }) it('should work when passed to injectQuery', () => { - const key = queryKey() + const key = createKey() const options = queryOptions({ queryKey: key, queryFn: () => Promise.resolve(5), @@ -82,7 +82,7 @@ describe('queryOptions', () => { }) it('should work when passed to fetchQuery', () => { - const key = queryKey() + const key = createKey() const options = queryOptions({ queryKey: key, queryFn: () => Promise.resolve(5), @@ -136,7 +136,7 @@ describe('queryOptions', () => { }) it('should tag the queryKey with the result type of the QueryFn', () => { - const key = queryKey() + const key = createKey() const { queryKey: tagged } = queryOptions({ queryKey: key, queryFn: () => Promise.resolve(5), @@ -145,7 +145,7 @@ describe('queryOptions', () => { }) it('should tag the queryKey even if no promise is returned', () => { - const key = queryKey() + const key = createKey() const { queryKey: tagged } = queryOptions({ queryKey: key, queryFn: () => 5, @@ -154,7 +154,7 @@ describe('queryOptions', () => { }) it('should tag the queryKey with unknown if there is no queryFn', () => { - const key = queryKey() + const key = createKey() const { queryKey: tagged } = queryOptions({ queryKey: key, }) @@ -163,7 +163,7 @@ describe('queryOptions', () => { }) it('should tag the queryKey with the result type of the QueryFn if select is used', () => { - const key = queryKey() + const key = createKey() const { queryKey: tagged } = queryOptions({ queryKey: key, queryFn: () => Promise.resolve(5), @@ -174,7 +174,7 @@ describe('queryOptions', () => { }) it('should return the proper type when passed to getQueryData', () => { - const key = queryKey() + const key = createKey() const { queryKey: tagged } = queryOptions({ queryKey: key, queryFn: () => Promise.resolve(5), @@ -187,7 +187,7 @@ describe('queryOptions', () => { }) it('should return the proper type when passed to getQueryState', () => { - const key = queryKey() + const key = createKey() const { queryKey: tagged } = queryOptions({ queryKey: key, queryFn: () => Promise.resolve(5), @@ -200,7 +200,7 @@ describe('queryOptions', () => { }) it('should properly type updaterFn when passed to setQueryData', () => { - const key = queryKey() + const key = createKey() const { queryKey: tagged } = queryOptions({ queryKey: key, queryFn: () => Promise.resolve(5), @@ -216,7 +216,7 @@ describe('queryOptions', () => { }) it('should properly type value when passed to setQueryData', () => { - const key = queryKey() + const key = createKey() const { queryKey: tagged } = queryOptions({ queryKey: key, queryFn: () => Promise.resolve(5), @@ -235,7 +235,7 @@ describe('queryOptions', () => { }) it('should infer even if there is a conditional skipToken', () => { - const key = queryKey() + const key = createKey() const options = queryOptions({ queryKey: key, queryFn: Math.random() > 0.5 ? skipToken : () => Promise.resolve(5), @@ -248,7 +248,7 @@ describe('queryOptions', () => { }) it('should infer to unknown if we disable a query with just a skipToken', () => { - const key = queryKey() + const key = createKey() const options = queryOptions({ queryKey: key, queryFn: skipToken, diff --git a/packages/angular-query-persist-client/src/__tests__/with-persist-query-client.test.ts b/packages/angular-query-persist-client/src/__tests__/with-persist-query-client.test.ts index a48186a352b..0a88718616f 100644 --- a/packages/angular-query-persist-client/src/__tests__/with-persist-query-client.test.ts +++ b/packages/angular-query-persist-client/src/__tests__/with-persist-query-client.test.ts @@ -12,7 +12,7 @@ import { provideZonelessChangeDetection, } from '@angular/core' import { render } from '@testing-library/angular' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { withPersistQueryClient } from '../with-persist-query-client' import type { PersistedClient, @@ -65,7 +65,7 @@ describe('withPersistQueryClient', () => { }) it('should restore cache from persister', async () => { - const key = queryKey() + const key = createKey() const states: Array<{ status: string fetchStatus: string @@ -157,7 +157,7 @@ describe('withPersistQueryClient', () => { ) it('should show initialData while restoring', async () => { - const key = queryKey() + const key = createKey() const states: Array<{ status: string fetchStatus: string @@ -249,7 +249,7 @@ describe('withPersistQueryClient', () => { }) it('should not refetch after restoring when data is fresh', async () => { - const key = queryKey() + const key = createKey() const states: Array<{ status: string fetchStatus: string @@ -337,7 +337,7 @@ describe('withPersistQueryClient', () => { }) it('should call onSuccess after successful restoring', async () => { - const key = queryKey() + const key = createKey() const queryClient = new QueryClient() void queryClient .query({ @@ -394,7 +394,7 @@ describe('withPersistQueryClient', () => { }) it('should remove cache after non-successful restoring', async () => { - const key = queryKey() + const key = createKey() const consoleErrorMock = vi .spyOn(console, 'error') .mockReturnValue(undefined) diff --git a/packages/lit-query/src/__tests__/QueryClientProvider.test.ts b/packages/lit-query/src/__tests__/QueryClientProvider.test.ts index 695447ae89a..0c27708a409 100644 --- a/packages/lit-query/src/__tests__/QueryClientProvider.test.ts +++ b/packages/lit-query/src/__tests__/QueryClientProvider.test.ts @@ -8,7 +8,7 @@ import { vi, } from 'vitest' import { QueryClient } from '@tanstack/query-core' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { LitElement } from 'lit' import { createQueryController } from '../createQueryController.js' import { @@ -195,7 +195,7 @@ describe('QueryClientProvider/context', () => { }) it('should tear down the mounted client before surfacing the error when a connected client is updated to an invalid value', async () => { - const key = queryKey() + const key = createKey() const mount = vi.spyOn(queryClient, 'mount') const unmount = vi.spyOn(queryClient, 'unmount') diff --git a/packages/lit-query/src/__tests__/createInfiniteQueryController.test-d.ts b/packages/lit-query/src/__tests__/createInfiniteQueryController.test-d.ts index ec95f83d32d..03d273b9fc0 100644 --- a/packages/lit-query/src/__tests__/createInfiniteQueryController.test-d.ts +++ b/packages/lit-query/src/__tests__/createInfiniteQueryController.test-d.ts @@ -1,5 +1,5 @@ import { QueryClient } from '@tanstack/query-core' -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { LitElement } from 'lit' import { describe, expectTypeOf, it } from 'vitest' import { createInfiniteQueryController } from '../createInfiniteQueryController.js' @@ -17,7 +17,7 @@ describe('pageParam', () => { createInfiniteQueryController( new Host(), { - queryKey: queryKey(), + queryKey: createKey(), queryFn: ({ pageParam }) => { expectTypeOf(pageParam).toEqualTypeOf() }, @@ -32,7 +32,7 @@ describe('pageParam', () => { createInfiniteQueryController( new Host(), { - queryKey: queryKey(), + queryKey: createKey(), queryFn: ({ direction }) => { expectTypeOf(direction).toEqualTypeOf<'forward' | 'backward'>() }, @@ -49,7 +49,7 @@ describe('select', () => { const infiniteQuery = createInfiniteQueryController( new Host(), { - queryKey: queryKey(), + queryKey: createKey(), queryFn: ({ pageParam }) => { return pageParam * 5 }, @@ -69,7 +69,7 @@ describe('select', () => { const infiniteQuery = createInfiniteQueryController( new Host(), { - queryKey: queryKey(), + queryKey: createKey(), queryFn: ({ pageParam }) => { return pageParam * 5 }, @@ -92,7 +92,7 @@ describe('getNextPageParam / getPreviousPageParam', () => { const infiniteQuery = createInfiniteQueryController( new Host(), { - queryKey: queryKey(), + queryKey: createKey(), queryFn: ({ pageParam }) => { return String(pageParam) }, @@ -137,7 +137,7 @@ describe('error booleans', () => { const infiniteQuery = createInfiniteQueryController( new Host(), { - queryKey: queryKey(), + queryKey: createKey(), queryFn: ({ pageParam }) => { return pageParam * 5 }, @@ -163,7 +163,7 @@ describe('error booleans', () => { describe('CreateInfiniteQueryOptions', () => { it('should default TData to InfiniteData', () => { const options: CreateInfiniteQueryOptions = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 5, initialPageParam: 1, getNextPageParam: () => undefined, @@ -185,7 +185,7 @@ describe('refetch / fetchNextPage / fetchPreviousPage', () => { const infiniteQuery = createInfiniteQueryController( new Host(), { - queryKey: queryKey(), + queryKey: createKey(), queryFn: ({ pageParam }) => pageParam, initialPageParam: 1, getNextPageParam: (lastPage) => lastPage + 1, @@ -203,7 +203,7 @@ describe('refetch / fetchNextPage / fetchPreviousPage', () => { const infiniteQuery = createInfiniteQueryController( new Host(), { - queryKey: queryKey(), + queryKey: createKey(), queryFn: ({ pageParam }) => pageParam, initialPageParam: 1, getNextPageParam: (lastPage) => lastPage + 1, @@ -221,7 +221,7 @@ describe('refetch / fetchNextPage / fetchPreviousPage', () => { const infiniteQuery = createInfiniteQueryController( new Host(), { - queryKey: queryKey(), + queryKey: createKey(), queryFn: ({ pageParam }) => pageParam, initialPageParam: 1, getNextPageParam: (lastPage) => lastPage + 1, diff --git a/packages/lit-query/src/__tests__/createInfiniteQueryController.test.ts b/packages/lit-query/src/__tests__/createInfiniteQueryController.test.ts index d38c76a271b..8984bfce143 100644 --- a/packages/lit-query/src/__tests__/createInfiniteQueryController.test.ts +++ b/packages/lit-query/src/__tests__/createInfiniteQueryController.test.ts @@ -8,7 +8,7 @@ import { vi, } from 'vitest' import { QueryClient, skipToken } from '@tanstack/query-core' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { LitElement, html } from 'lit' import { QueryClientProvider } from '../QueryClientProvider.js' import { createInfiniteQueryController } from '../createInfiniteQueryController.js' @@ -41,7 +41,7 @@ describe('createInfiniteQueryController', () => { }) it('should resolve from the pre-connect placeholder state on the first provider connection', async () => { - const key = queryKey() + const key = createKey() class Consumer extends LitElement { readonly queryKey = key @@ -95,7 +95,7 @@ describe('createInfiniteQueryController', () => { }) it('should prefer an explicit client over the provider context', async () => { - const key = queryKey() + const key = createKey() const providerClient = new QueryClient() const provider = document.createElement( @@ -150,7 +150,7 @@ describe('createInfiniteQueryController', () => { }) it('should fetch the initial page', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { readonly infinite = createInfiniteQueryController( @@ -186,7 +186,7 @@ describe('createInfiniteQueryController', () => { }) it('should append the next page with fetchNextPage', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { readonly infinite = createInfiniteQueryController( @@ -223,7 +223,7 @@ describe('createInfiniteQueryController', () => { }) it('should prepend the previous page with fetchPreviousPage', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { readonly infinite = createInfiniteQueryController( @@ -260,7 +260,7 @@ describe('createInfiniteQueryController', () => { }) it('should not cancel an ongoing fetchNextPage request when another fetchNextPage is invoked if `cancelRefetch: false` is used', async () => { - const key = queryKey() + const key = createKey() const start = 10 const onAborts: Array) => any>> = [] const abortListeners: Array) => any>> = [] @@ -329,7 +329,7 @@ describe('createInfiniteQueryController', () => { }) it('should not request another update when stable function options refresh during host update', async () => { - const key = queryKey() + const key = createKey() let callCount = 0 class Host extends LitElement { @@ -387,7 +387,7 @@ describe('createInfiniteQueryController', () => { }) it('should not request an update for refetch-only state changes when only data was read', async () => { - const key = queryKey() + const key = createKey() let resolveRefetch: (() => void) | undefined class Host extends LitElement { @@ -447,7 +447,7 @@ describe('createInfiniteQueryController', () => { }) it('should refresh a suppressed result on the next accessor read when a newly read property changed', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { updatesRequested = 0 @@ -501,7 +501,7 @@ describe('createInfiniteQueryController', () => { }) it('should return the same result between reads when nothing changed', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { readonly infinite = createInfiniteQueryController( @@ -527,7 +527,7 @@ describe('createInfiniteQueryController', () => { }) it('should preserve prior pages consistently when fetching the next page fails', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { readonly infinite = createInfiniteQueryController( @@ -580,7 +580,7 @@ describe('createInfiniteQueryController', () => { }) it('should cancel the query function when there are no more subscriptions', async () => { - const key = queryKey() + const key = createKey() let cancelFn: Mock = vi.fn<(event: Event) => void>() const queryFn = ({ signal }: { signal?: AbortSignal }) => { @@ -624,7 +624,7 @@ describe('createInfiniteQueryController', () => { }) it('should not fetch when queryFn is skipToken, and fetch once it is replaced', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<(context: { pageParam: number }) => Promise>( ({ pageParam }: { pageParam: number }) => sleep(10).then(() => `comments for 1 page ${pageParam}`), @@ -671,7 +671,7 @@ describe('createInfiniteQueryController', () => { }) it('should fail deterministically and align imperative methods when the provider is missing', async () => { - const key = queryKey() + const key = createKey() class Consumer extends LitElement { readonly queryKey = key @@ -722,7 +722,7 @@ describe('createInfiniteQueryController', () => { }) it('should reuse hydrated data on an already-connected host without an eager refetch', async () => { - const key = queryKey() + const key = createKey() let queryFnCalls = 0 queryClient.setQueryData(key, { pages: [0], pageParams: [0] }) @@ -764,7 +764,7 @@ describe('createInfiniteQueryController', () => { }) it('should not throw for an infinite query controller on an already-connected host with an explicit client', async () => { - const key = queryKey() + const key = createKey() queryClient.setQueryData(key, { pages: [0], pageParams: [0], @@ -801,7 +801,7 @@ describe('createInfiniteQueryController', () => { }) it('should defer explicit-client infinite accessors until host fields are initialized', async () => { - const key = queryKey() + const key = createKey() class DeferredExplicitInfiniteHost extends LitElement { readonly infinite = createInfiniteQueryController( @@ -842,7 +842,7 @@ describe('createInfiniteQueryController', () => { }) it('should switch infinite query controller to new provider client while connected', async () => { - const key = queryKey() + const key = createKey() const clientA = new QueryClient() const clientB = new QueryClient() @@ -918,7 +918,7 @@ describe('createInfiniteQueryController', () => { }) it('should reparent infinite query controller under a different provider and bind the new nearest client', async () => { - const key = queryKey() + const key = createKey() const clientA = new QueryClient() const clientB = new QueryClient() diff --git a/packages/lit-query/src/__tests__/createMutationController.test.ts b/packages/lit-query/src/__tests__/createMutationController.test.ts index e5c80972233..647be878c76 100644 --- a/packages/lit-query/src/__tests__/createMutationController.test.ts +++ b/packages/lit-query/src/__tests__/createMutationController.test.ts @@ -8,7 +8,7 @@ import { vi, } from 'vitest' import { QueryClient, noop } from '@tanstack/query-core' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { LitElement, html } from 'lit' import { QueryClientProvider } from '../QueryClientProvider.js' import { createMutationController } from '../createMutationController.js' @@ -39,7 +39,7 @@ describe('createMutationController', () => { }) it('should resolve from the pre-connect placeholder state on the first provider connection', async () => { - const key = queryKey() + const key = createKey() class Consumer extends LitElement { readonly mutationKey = key @@ -87,7 +87,7 @@ describe('createMutationController', () => { }) it('should prefer an explicit client over the provider context', async () => { - const key = queryKey() + const key = createKey() const providerClient = new QueryClient() const provider = document.createElement( @@ -192,7 +192,7 @@ describe('createMutationController', () => { }) it('should be able to use mutation defaults', async () => { - const key = queryKey() + const key = createKey() queryClient.setMutationDefaults(key, { mutationFn: (text: string) => sleep(10).then(() => text), @@ -823,7 +823,7 @@ describe('createMutationController', () => { }) it('should become a deterministic missing-client state when the provider is missing', async () => { - const key = queryKey() + const key = createKey() class Consumer extends LitElement { readonly mutationKey = key @@ -863,7 +863,7 @@ describe('createMutationController', () => { }) it('should recover without reconstruction when a valid provider is adopted later', async () => { - const key = queryKey() + const key = createKey() class Consumer extends LitElement { readonly mutationKey = key @@ -915,7 +915,7 @@ describe('createMutationController', () => { host.mutation = createMutationController( host, { - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: (value: number) => sleep(10).then(() => value * 2), }, queryClient, @@ -937,7 +937,7 @@ describe('createMutationController', () => { }) it('should defer explicit-client mutation accessors until host fields are initialized', async () => { - const key = queryKey() + const key = createKey() class DeferredExplicitMutationHost extends LitElement { readonly mutation = createMutationController( @@ -978,7 +978,7 @@ describe('createMutationController', () => { }) it('should switch mutation controller to new provider client while connected', async () => { - const key = queryKey() + const key = createKey() const clientA = new QueryClient() const clientB = new QueryClient() @@ -1073,7 +1073,7 @@ describe('createMutationController', () => { }) it('should reparent mutation controller under a different provider and bind the new nearest client', async () => { - const key = queryKey() + const key = createKey() const clientA = new QueryClient() const clientB = new QueryClient() diff --git a/packages/lit-query/src/__tests__/createQueriesController.test-d.ts b/packages/lit-query/src/__tests__/createQueriesController.test-d.ts index 414bc6b81bb..e4bafc5ecf7 100644 --- a/packages/lit-query/src/__tests__/createQueriesController.test-d.ts +++ b/packages/lit-query/src/__tests__/createQueriesController.test-d.ts @@ -1,5 +1,5 @@ import { QueryClient, skipToken } from '@tanstack/query-core' -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { LitElement } from 'lit' import { describe, expectTypeOf, it } from 'vitest' import { createQueriesController } from '../createQueriesController.js' @@ -19,7 +19,7 @@ describe('createQueriesController', () => { describe('config object overload', () => { it('should always define TData when initialData is provided as an object', () => { const query1 = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => { return { wow: true, @@ -31,13 +31,13 @@ describe('createQueriesController', () => { } const query2 = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 'Query Data', initialData: 'initial data', } const query3 = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 'Query Data', } @@ -58,7 +58,7 @@ describe('createQueriesController', () => { it('should define TData when passed through queryOptions', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => { return { wow: true, @@ -81,13 +81,13 @@ describe('createQueriesController', () => { it('should be possible to define a different TData than TQueryFnData using select with queryOptions spread into createQueriesController', () => { const query1 = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), select: (data) => data > 1, }) const query2 = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), select: (data: number) => data > 1, } @@ -110,7 +110,7 @@ describe('createQueriesController', () => { { queries: [ { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => { return { wow: true, @@ -141,7 +141,7 @@ describe('createQueriesController', () => { queries: [ { ...options, - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('data'), }, ], @@ -163,7 +163,7 @@ describe('createQueriesController', () => { { queries: [ { - queryKey: queryKey(), + queryKey: createKey(), queryFn: Math.random() > 0.5 ? skipToken : () => Promise.resolve(5), }, @@ -184,14 +184,14 @@ describe('createQueriesController', () => { const Queries1 = { get: () => queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), }), } const Queries2 = { get: () => queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(true), }), } @@ -216,9 +216,9 @@ describe('createQueriesController', () => { describe('type parameters', () => { it('should handle type parameter - tuple of tuples', () => { - const key1 = queryKey() - const key2 = queryKey() - const key3 = queryKey() + const key1 = createKey() + const key2 = createKey() + const key3 = createKey() const result1 = createQueriesController< [[number], [string], [Array, boolean]] @@ -344,9 +344,9 @@ describe('createQueriesController', () => { }) it('should handle type parameter - tuple of objects', () => { - const key1 = queryKey() - const key2 = queryKey() - const key3 = queryKey() + const key1 = createKey() + const key2 = createKey() + const key3 = createKey() const result1 = createQueriesController< [ @@ -524,7 +524,7 @@ describe('createQueriesController', () => { { queries: [ queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 'string', select: (a) => { expectTypeOf(a).toEqualTypeOf() @@ -532,7 +532,7 @@ describe('createQueriesController', () => { }, }), queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 'string', select: (a) => { expectTypeOf(a).toEqualTypeOf() @@ -554,11 +554,11 @@ describe('createQueriesController', () => { }) it('should handle array literal without type parameter to infer result type', () => { - const key1 = queryKey() - const key2 = queryKey() - const key3 = queryKey() - const key4 = queryKey() - const key5 = queryKey() + const key1 = createKey() + const key2 = createKey() + const key3 = createKey() + const key4 = createKey() + const key5 = createKey() type BizError = { code: number } const throwOnError = (_error: BizError) => true @@ -1066,7 +1066,7 @@ describe('createQueriesController', () => { { queries: [ { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), select: (data) => { expectTypeOf(data).toBeUnknown() @@ -1086,7 +1086,7 @@ describe('createQueriesController', () => { { queries: [ { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), select: (data: number) => data.toFixed(), }, @@ -1101,7 +1101,7 @@ describe('createQueriesController', () => { describe('with queryOptions passed directly', () => { it('should infer the queryFn data as the result without select', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), }) const queryResults = createQueriesController( @@ -1114,7 +1114,7 @@ describe('createQueriesController', () => { it('should infer the select argument and the result with select', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), select: (data) => { expectTypeOf(data).toEqualTypeOf() @@ -1131,7 +1131,7 @@ describe('createQueriesController', () => { it('should infer select when a base queryOptions is re-wrapped with queryOptions', () => { const baseOptions = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), }) const queryResults = createQueriesController( @@ -1156,7 +1156,7 @@ describe('createQueriesController', () => { it('should infer an overriding select when a queryOptions with a select is re-wrapped with queryOptions', () => { const baseOptions = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), select: (data) => data + 1, }) @@ -1182,7 +1182,7 @@ describe('createQueriesController', () => { describe('with queryOptions spread into an inline query object', () => { it('should leave an unannotated select as `unknown` without select in the factory', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), }) createQueriesController( @@ -1205,7 +1205,7 @@ describe('createQueriesController', () => { it('should compile an annotated select without select in the factory', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), }) const queryResults = createQueriesController( @@ -1220,7 +1220,7 @@ describe('createQueriesController', () => { it('should leave an unannotated overriding select as `unknown` with select in the factory', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), select: (data) => data + 1, }) @@ -1244,7 +1244,7 @@ describe('createQueriesController', () => { it('should compile an annotated overriding select with select in the factory', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), select: (data) => data + 1, }) @@ -1267,11 +1267,11 @@ describe('createQueriesController', () => { { queries: [ { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(7), }, { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('ok'), }, ], @@ -1293,7 +1293,7 @@ describe('createQueriesController', () => { { queries: [ queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve({ id: 5, name: 'Katherine' }), initialData: { id: 1, name: 'Init' }, }), diff --git a/packages/lit-query/src/__tests__/createQueriesController.test.ts b/packages/lit-query/src/__tests__/createQueriesController.test.ts index 1f86085fa1e..b8be0eda2ac 100644 --- a/packages/lit-query/src/__tests__/createQueriesController.test.ts +++ b/packages/lit-query/src/__tests__/createQueriesController.test.ts @@ -8,7 +8,7 @@ import { vi, } from 'vitest' import { QueryClient } from '@tanstack/query-core' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { LitElement, html } from 'lit' import { QueryClientProvider } from '../QueryClientProvider.js' import { createQueriesController } from '../createQueriesController.js' @@ -41,7 +41,7 @@ describe('createQueriesController', () => { }) it('should resolve from the pre-connect placeholder state on the first provider connection', async () => { - const key = queryKey() + const key = createKey() class Consumer extends LitElement { readonly queryKeys = [ @@ -103,7 +103,7 @@ describe('createQueriesController', () => { }) it('should prefer an explicit client over the provider context', async () => { - const key = queryKey() + const key = createKey() const providerClient = new QueryClient() const provider = document.createElement( @@ -168,8 +168,8 @@ describe('createQueriesController', () => { }) it('should combine multiple query results', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() class Host extends LitElement { readonly queries = createQueriesController( @@ -209,7 +209,7 @@ describe('createQueriesController', () => { }) it('should not have stale closures with combine (#6648)', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { static override properties = { count: { type: Number } } @@ -257,7 +257,7 @@ describe('createQueriesController', () => { }) it('should not request another update when stable function query options refresh during host update', async () => { - const key = queryKey() + const key = createKey() let callCount = 0 class Host extends LitElement { @@ -317,7 +317,7 @@ describe('createQueriesController', () => { }) it('should not request an update for refetch-only state changes when data was read and result refetch is invoked', async () => { - const key = queryKey() + const key = createKey() let resolveRefetch: (() => void) | undefined class Host extends LitElement { @@ -384,7 +384,7 @@ describe('createQueriesController', () => { return originalDefaultQueryOptions.call(queryClient, options as never) }) as typeof queryClient.defaultQueryOptions - const key = queryKey() + const key = createKey() let resolveRefetch: (() => void) | undefined class Host extends LitElement { @@ -437,7 +437,7 @@ describe('createQueriesController', () => { }) it('should refresh suppressed query results on the next accessor read when a newly read property changed', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { updatesRequested = 0 @@ -489,7 +489,7 @@ describe('createQueriesController', () => { }) it('should return the same result between reads when nothing changed', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { readonly queries = createQueriesController( @@ -517,9 +517,9 @@ describe('createQueriesController', () => { }) it('should support dynamic add/remove and keep partial failure stability', async () => { - const key1 = queryKey() - const key2 = queryKey() - const key3 = queryKey() + const key1 = createKey() + const key2 = createKey() + const key3 = createKey() let includeThird = false let includeFailing = true @@ -612,7 +612,7 @@ describe('createQueriesController', () => { }) it('should preserve the documented result order mapping when queries are reordered', async () => { - const key = queryKey() + const key = createKey() let order: Array<'first' | 'second'> = ['first', 'second'] class Host extends LitElement { @@ -651,7 +651,7 @@ describe('createQueriesController', () => { }) it('should return stable per-index results for duplicate query keys', async () => { - const key = queryKey() + const key = createKey() let callCount = 0 class Host extends LitElement { @@ -711,7 +711,7 @@ describe('createQueriesController', () => { }) it('should not process detached updates when disconnected while in-flight', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { updatesRequested = 0 @@ -750,7 +750,7 @@ describe('createQueriesController', () => { }) it('should fail after the handshake when the provider is missing and recover when a provider is adopted later', async () => { - const key = queryKey() + const key = createKey() class Consumer extends LitElement { readonly queryKeys = [ @@ -807,7 +807,7 @@ describe('createQueriesController', () => { }) it('should reject placeholder refetch of raw query results after the missing-client handshake', async () => { - const key = queryKey() + const key = createKey() class Consumer extends LitElement { readonly queryKeys = [ @@ -842,7 +842,7 @@ describe('createQueriesController', () => { }) it('should defer placeholder accessors in the constructor until host fields are initialized', () => { - const key = queryKey() + const key = createKey() class DeferredFieldsQueriesHost extends LitElement { readonly queries = createQueriesController(this, () => ({ @@ -867,7 +867,7 @@ describe('createQueriesController', () => { }) it('should re-surface permanent placeholder combine errors after initialization', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { readonly queries = createQueriesController(this, { @@ -896,7 +896,7 @@ describe('createQueriesController', () => { }) it('should materialize defined initialData in placeholder combine before a client is available', () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { readonly queries = createQueriesController(this, { @@ -921,7 +921,7 @@ describe('createQueriesController', () => { }) it('should call initialData and initialDataUpdatedAt functions in placeholder combine before a client is available', () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { readonly queries = createQueriesController(this, { @@ -950,7 +950,7 @@ describe('createQueriesController', () => { }) it('should apply select to initialData in placeholder combine before a client is available', () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { readonly queries = createQueriesController(this, { @@ -976,7 +976,7 @@ describe('createQueriesController', () => { }) it('should defer dynamic accessors in the explicit-client constructor until host fields are initialized', async () => { - const key = queryKey() + const key = createKey() class DeferredExplicitQueriesHost extends LitElement { readonly queries = createQueriesController( @@ -1011,7 +1011,7 @@ describe('createQueriesController', () => { }) it('should defer static combine callbacks in the explicit-client constructor until host fields are initialized', async () => { - const key = queryKey() + const key = createKey() class DeferredExplicitCombineQueriesHost extends LitElement { readonly queries = createQueriesController( @@ -1052,7 +1052,7 @@ describe('createQueriesController', () => { }) it('should re-surface permanent static combine errors in the explicit-client constructor after initialization', async () => { - const key = queryKey() + const key = createKey() class InvalidExplicitCombineQueriesHost extends LitElement { readonly queries = createQueriesController( @@ -1086,7 +1086,7 @@ describe('createQueriesController', () => { }) it('should reuse hydrated data on an already-connected host without an eager refetch', async () => { - const key = queryKey() + const key = createKey() let queryFnCalls = 0 queryClient.setQueryData(key, 'hydrated-value') @@ -1130,8 +1130,8 @@ describe('createQueriesController', () => { }) it('should not throw for a queries controller on an already-connected host with an explicit client', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() queryClient.setQueryData(key1, 'alpha') queryClient.setQueryData(key2, 'beta') @@ -1184,7 +1184,7 @@ describe('createQueriesController', () => { }) it('should switch queries controller to new provider client while connected', async () => { - const key = queryKey() + const key = createKey() const clientA = new QueryClient() const clientB = new QueryClient() @@ -1257,7 +1257,7 @@ describe('createQueriesController', () => { }) it('should reparent queries controller under a different provider without cross-tree leakage', async () => { - const key = queryKey() + const key = createKey() const clientA = new QueryClient() const clientB = new QueryClient() diff --git a/packages/lit-query/src/__tests__/createQueryController.test-d.ts b/packages/lit-query/src/__tests__/createQueryController.test-d.ts index 34e3f0618a7..64f4a14f56f 100644 --- a/packages/lit-query/src/__tests__/createQueryController.test-d.ts +++ b/packages/lit-query/src/__tests__/createQueryController.test-d.ts @@ -1,5 +1,5 @@ import { QueryClient } from '@tanstack/query-core' -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { LitElement } from 'lit' import { assertType, describe, expectTypeOf, it } from 'vitest' import { createQueryController } from '../createQueryController.js' @@ -17,7 +17,7 @@ describe('createQueryController', () => { it('should default data to unknown when the query function is not specified', () => { const query = createQueryController( new Host(), - { queryKey: queryKey() }, + { queryKey: createKey() }, new QueryClient(), ) @@ -28,7 +28,7 @@ describe('createQueryController', () => { it('should infer the result type from the query function', () => { const query = createQueryController( new Host(), - { queryKey: queryKey(), queryFn: () => 'test' }, + { queryKey: createKey(), queryFn: () => 'test' }, new QueryClient(), ) @@ -39,7 +39,7 @@ describe('createQueryController', () => { it('should be possible to specify the result type', () => { const query = createQueryController( new Host(), - { queryKey: queryKey(), queryFn: () => 'test' }, + { queryKey: createKey(), queryFn: () => 'test' }, new QueryClient(), ) @@ -50,7 +50,7 @@ describe('createQueryController', () => { it('should be possible to specify the error type', () => { const query = createQueryController( new Host(), - { queryKey: queryKey(), queryFn: () => 'test' }, + { queryKey: createKey(), queryFn: () => 'test' }, new QueryClient(), ) @@ -62,7 +62,7 @@ describe('createQueryController', () => { const unionTypeSync = createQueryController( new Host(), { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => (Math.random() > 0.5 ? ('a' as const) : ('b' as const)), }, new QueryClient(), @@ -72,7 +72,7 @@ describe('createQueryController', () => { const unionTypeAsync = createQueryController<'a' | 'b'>( new Host(), { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(Math.random() > 0.5 ? 'a' : 'b'), }, new QueryClient(), @@ -85,7 +85,7 @@ describe('createQueryController', () => { createQueryController( new Host(), // @ts-expect-error - { queryKey: queryKey(), queryFn: () => 'test' }, + { queryKey: createKey(), queryFn: () => 'test' }, new QueryClient(), ), ) @@ -98,7 +98,7 @@ describe('createQueryController', () => { const query = createQueryController( new Host(), - { queryKey: queryKey(), queryFn: () => queryFn() }, + { queryKey: createKey(), queryFn: () => queryFn() }, new QueryClient(), ) @@ -194,7 +194,7 @@ describe('createQueryController', () => { it('should return the correct states for a successful query', () => { const query = createQueryController( new Host(), - { queryKey: queryKey(), queryFn: () => Promise.resolve('test') }, + { queryKey: createKey(), queryFn: () => Promise.resolve('test') }, new QueryClient(), ) const state = query() @@ -218,7 +218,7 @@ describe('createQueryController', () => { it('should type refetch with correct return type', () => { const query = createQueryController( new Host(), - { queryKey: queryKey(), queryFn: () => Promise.resolve('test') }, + { queryKey: createKey(), queryFn: () => Promise.resolve('test') }, new QueryClient(), ) @@ -230,7 +230,7 @@ describe('createQueryController', () => { it('should type suspense with correct return type', () => { const query = createQueryController( new Host(), - { queryKey: queryKey(), queryFn: () => Promise.resolve('test') }, + { queryKey: createKey(), queryFn: () => Promise.resolve('test') }, new QueryClient(), ) @@ -243,7 +243,7 @@ describe('createQueryController', () => { describe('Config object overload', () => { it('should be possible to define a different TData than TQueryFnData using select with queryOptions spread into createQueryController', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), }) const query = createQueryController( @@ -258,7 +258,7 @@ describe('createQueryController', () => { it('should have undefined in the TData union when initialData is NOT provided', () => { const query = createQueryController( new Host(), - { queryKey: queryKey(), queryFn: () => ({ wow: true }) }, + { queryKey: createKey(), queryFn: () => ({ wow: true }) }, new QueryClient(), ) @@ -269,7 +269,7 @@ describe('createQueryController', () => { const query = createQueryController( new Host(), { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => ({ wow: true }), initialData: () => undefined as { wow: boolean } | undefined, }, @@ -283,7 +283,7 @@ describe('createQueryController', () => { const query = createQueryController( new Host(), { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => ({ wow: true }), initialData: () => undefined as { wow: boolean } | undefined, }, @@ -304,7 +304,7 @@ describe('createQueryController', () => { const query = createQueryController( new Host(), { - queryKey: queryKey(), + queryKey: createKey(), queryFn: (): Result => ({ type: 'first', first: 'a' }), }, new QueryClient(), @@ -330,7 +330,7 @@ describe('createQueryController', () => { new Host(), { ...options, - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('data'), }, new QueryClient(), @@ -347,7 +347,7 @@ describe('createQueryController', () => { createQueryController( new Host(), { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 5, structuralSharing: (oldData, newData) => { expectTypeOf(oldData).toBeUnknown() diff --git a/packages/lit-query/src/__tests__/createQueryController.test.ts b/packages/lit-query/src/__tests__/createQueryController.test.ts index 718accbd7e9..064140be4e2 100644 --- a/packages/lit-query/src/__tests__/createQueryController.test.ts +++ b/packages/lit-query/src/__tests__/createQueryController.test.ts @@ -8,7 +8,7 @@ import { vi, } from 'vitest' import { QueryClient, keepPreviousData } from '@tanstack/query-core' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { LitElement, html } from 'lit' import { QueryClientProvider } from '../QueryClientProvider.js' import { createQueryController } from '../createQueryController.js' @@ -39,7 +39,7 @@ describe('createQueryController', () => { }) it('should not request update after destroy when microtask flushes', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { updatesRequested = 0 @@ -72,7 +72,7 @@ describe('createQueryController', () => { }) it('should remove the observer from the query when destroyed', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { readonly query = createQueryController( @@ -102,7 +102,7 @@ describe('createQueryController', () => { }) it('should return observer count to baseline after 100 lifecycle cycles', async () => { - const key = queryKey() + const key = createKey() for (let cycle = 0; cycle < 100; cycle += 1) { class Host extends LitElement { @@ -133,7 +133,7 @@ describe('createQueryController', () => { }) it('should fetch and update query state', async () => { - const key = queryKey() + const key = createKey() let callCount = 0 @@ -170,7 +170,7 @@ describe('createQueryController', () => { }) it('should not request another update when stable function options refresh during host update', async () => { - const key = queryKey() + const key = createKey() let callCount = 0 @@ -226,7 +226,7 @@ describe('createQueryController', () => { }) it('should not request an update for refetch-only state changes when only data was read', async () => { - const key = queryKey() + const key = createKey() let resolveRefetch: (() => void) | undefined class Host extends LitElement { @@ -281,7 +281,7 @@ describe('createQueryController', () => { }) it('should refresh a suppressed result on the next accessor read when a newly read property changed', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { updatesRequested = 0 @@ -329,7 +329,7 @@ describe('createQueryController', () => { }) it('should return the same result between reads when nothing changed', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { readonly query = createQueryController( @@ -353,7 +353,7 @@ describe('createQueryController', () => { }) it('should transition from pending to success with expected contract', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { readonly query = createQueryController( @@ -389,7 +389,7 @@ describe('createQueryController', () => { }) it('should not fetch when enabled=false and fetch after enabling', async () => { - const key = queryKey() + const key = createKey() let callCount = 0 let enabled = false @@ -436,7 +436,7 @@ describe('createQueryController', () => { }) it('should not cancel an ongoing fetch when refetch is called with cancelRefetch=false if we have data already', async () => { - const key = queryKey() + const key = createKey() let fetchCount = 0 class Host extends LitElement { @@ -473,7 +473,7 @@ describe('createQueryController', () => { }) it('should not leak observers and should refetch on remount with gcTime=0', async () => { - const key = queryKey() + const key = createKey() let callCount = 0 class Host extends LitElement { @@ -529,7 +529,7 @@ describe('createQueryController', () => { }) it('should apply latest accessor key/options on updates and refetch', async () => { - const key = queryKey() + const key = createKey() let keyId = 1 const seenKeys: Array = [] @@ -580,7 +580,7 @@ describe('createQueryController', () => { }) it('should not request a host update when function options resolve to an unchanged result', async () => { - const key = queryKey() + const key = createKey() let callCount = 0 @@ -631,7 +631,7 @@ describe('createQueryController', () => { }) it('should refetch on mount when the data is stale', async () => { - const key = queryKey() + const key = createKey() let callCount = 0 class Host extends LitElement { @@ -673,7 +673,7 @@ describe('createQueryController', () => { }) it('should not refetch on mount when the data is fresh', async () => { - const key = queryKey() + const key = createKey() let callCount = 0 class Host extends LitElement { @@ -721,7 +721,7 @@ describe('createQueryController', () => { }) it('should transform data with select', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { readonly query = createQueryController( @@ -751,7 +751,7 @@ describe('createQueryController', () => { }) it('should surface a throwing select as an error', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { readonly query = createQueryController( @@ -786,7 +786,7 @@ describe('createQueryController', () => { }) it('should preserve prior data during key transitions with keepPreviousData', async () => { - const key = queryKey() + const key = createKey() let keyId = 1 let resolveSecond: ((value: string) => void) | undefined @@ -850,7 +850,7 @@ describe('createQueryController', () => { }) it('should refetch and update result state on invalidation', async () => { - const key = queryKey() + const key = createKey() let callCount = 0 class Host extends LitElement { @@ -891,7 +891,7 @@ describe('createQueryController', () => { }) it('should not overwrite a newer key result with a stale older response', async () => { - const key = queryKey() + const key = createKey() let keyId = 'old' let resolveOld: ((value: string) => void) | undefined @@ -947,7 +947,7 @@ describe('createQueryController', () => { }) it('should pass an AbortSignal to queryFn and abort the prior request on key switch', async () => { - const key = queryKey() + const key = createKey() let keyId: 'old' | 'new' = 'old' let oldSignal: AbortSignal | undefined @@ -1002,7 +1002,7 @@ describe('createQueryController', () => { }) it('should maintain a stable final state without duplicate observers under rapid key churn', async () => { - const key = queryKey() + const key = createKey() let keyId = 0 @@ -1046,7 +1046,7 @@ describe('createQueryController', () => { }) it('should not process detached updates when disconnected while in-flight', async () => { - const key = queryKey() + const key = createKey() let resolveFetch: ((value: string) => void) | undefined @@ -1091,7 +1091,7 @@ describe('createQueryController', () => { }) it('should yield a correct snapshot when reconnecting after an in-flight request settles', async () => { - const key = queryKey() + const key = createKey() let resolveFetch: ((value: string) => void) | undefined @@ -1134,7 +1134,7 @@ describe('createQueryController', () => { }) it('should use the latest select closure after host updates', async () => { - const key = queryKey() + const key = createKey() let multiplier = 1 @@ -1181,7 +1181,7 @@ describe('createQueryController', () => { }) it('should switch provider client while connected with a single active observer', async () => { - const key = queryKey() + const key = createKey() const clientA = new QueryClient() const clientB = new QueryClient() @@ -1241,7 +1241,7 @@ describe('createQueryController', () => { }) it('should track retry failure metadata before eventual success', async () => { - const key = queryKey() + const key = createKey() let attempts = 0 @@ -1288,7 +1288,7 @@ describe('createQueryController', () => { }) it('should be reconnect-idempotent without duplicate subscriptions', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { readonly query = createQueryController( @@ -1326,7 +1326,7 @@ describe('createQueryController', () => { }) it('should be safe before provider resolution in the no-explicit-client constructor path', async () => { - const key = queryKey() + const key = createKey() class Consumer extends LitElement { readonly queryKey = key @@ -1371,7 +1371,7 @@ describe('createQueryController', () => { }) it('should not spuriously throw during the handshake on the first provider-backed connection', async () => { - const key = queryKey() + const key = createKey() const provider = document.createElement( providerTagName, @@ -1416,7 +1416,7 @@ describe('createQueryController', () => { }) it('should throw after the initial placeholder phase when no provider is available', async () => { - const key = queryKey() + const key = createKey() class Consumer extends LitElement { readonly queryKey = key @@ -1453,7 +1453,7 @@ describe('createQueryController', () => { }) it('should share the missing-client contract between wrapper and result-object imperative methods', async () => { - const key = queryKey() + const key = createKey() class Consumer extends LitElement { readonly queryKey = key @@ -1488,7 +1488,7 @@ describe('createQueryController', () => { }) it('should clear stale provider-derived client state when reconnecting outside any provider', async () => { - const key = queryKey() + const key = createKey() const provider = document.createElement( providerTagName, @@ -1544,7 +1544,7 @@ describe('createQueryController', () => { }) it('should rebind cleanly with later recovery when reconnecting under a different provider', async () => { - const key = queryKey() + const key = createKey() const clientA = new QueryClient() const clientB = new QueryClient() const providerA = document.createElement( @@ -1620,7 +1620,7 @@ describe('createQueryController', () => { }) it('should reuse hydrated data on an already-connected host without an eager refetch', async () => { - const key = queryKey() + const key = createKey() let queryFnCalls = 0 queryClient.setQueryData(key, 'hydrated-value') @@ -1672,7 +1672,7 @@ describe('createQueryController', () => { }) it('should defer explicit-client query accessors until host fields are initialized', async () => { - const key = queryKey() + const key = createKey() class DeferredExplicitQueryHost extends LitElement { readonly query = createQueryController( @@ -1710,7 +1710,7 @@ describe('createQueryController', () => { }) it('should fetch and resolve with the fetched result from suspense when the data is stale', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => sleep(10).then(() => 'data'), ) @@ -1748,7 +1748,7 @@ describe('createQueryController', () => { }) it('should resolve immediately without refetching from suspense when the data is fresh', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => sleep(10).then(() => 'data'), ) @@ -1790,7 +1790,7 @@ describe('createQueryController', () => { }) it('should resolve with the current result without fetching from suspense when disabled', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => sleep(10).then(() => 'data'), ) @@ -1827,7 +1827,7 @@ describe('createQueryController', () => { }) it('should apply the latest options to the controller before resolving from suspense', async () => { - const key = queryKey() + const key = createKey() class Host extends LitElement { userId = 1 diff --git a/packages/lit-query/src/__tests__/infiniteQueryOptions.test-d.ts b/packages/lit-query/src/__tests__/infiniteQueryOptions.test-d.ts index 3f0c74daf2a..42c7b9067f0 100644 --- a/packages/lit-query/src/__tests__/infiniteQueryOptions.test-d.ts +++ b/packages/lit-query/src/__tests__/infiniteQueryOptions.test-d.ts @@ -4,7 +4,7 @@ import { dataTagSymbol, skipToken, } from '@tanstack/query-core' -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { LitElement } from 'lit' import { assertType, describe, expectTypeOf, it } from 'vitest' import { createInfiniteQueryController } from '../createInfiniteQueryController.js' @@ -21,7 +21,7 @@ describe('infiniteQueryOptions', () => { it('should not allow excess properties', () => { assertType( infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('data'), getNextPageParam: () => 1, initialPageParam: 1, @@ -33,7 +33,7 @@ describe('infiniteQueryOptions', () => { it('should infer types for callbacks', () => { infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('data'), staleTime: 1000, getNextPageParam: () => 1, @@ -48,7 +48,7 @@ describe('infiniteQueryOptions', () => { const infinite = createInfiniteQueryController( new Host(), infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), initialPageParam: 0, queryFn: () => Promise.resolve({ page: 1 }), getNextPageParam: (lastPage) => lastPage.page + 1, @@ -65,7 +65,7 @@ describe('infiniteQueryOptions', () => { const infinite = createInfiniteQueryController( new Host(), infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('string'), getNextPageParam: () => 1, initialPageParam: 1, @@ -79,7 +79,7 @@ describe('infiniteQueryOptions', () => { it('should work when passed to infiniteQuery', async () => { const options = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('data'), getNextPageParam: () => 1, initialPageParam: 1, @@ -91,7 +91,7 @@ describe('infiniteQueryOptions', () => { it('should work when passed to infiniteQuery with select', async () => { const options = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('data'), getNextPageParam: () => 1, initialPageParam: 1, @@ -104,7 +104,7 @@ describe('infiniteQueryOptions', () => { it('should work when passed to infiniteQuery with enabled: false', async () => { const options = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('data'), getNextPageParam: () => 1, initialPageParam: 1, @@ -117,7 +117,7 @@ describe('infiniteQueryOptions', () => { it('should work when passed to infiniteQuery with skipToken', async () => { const options = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: skipToken, getNextPageParam: () => 1, initialPageParam: 1, @@ -129,7 +129,7 @@ describe('infiniteQueryOptions', () => { it('should tag the queryKey with the result type of the QueryFn', () => { const { queryKey: tagged } = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), initialPageParam: 0, queryFn: () => Promise.resolve({ page: 3 }), getNextPageParam: (lastPage) => lastPage.page + 1, @@ -143,7 +143,7 @@ describe('infiniteQueryOptions', () => { it('should tag the queryKey even if no promise is returned', () => { const { queryKey: tagged } = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 'string', getNextPageParam: () => 1, initialPageParam: 1, @@ -154,7 +154,7 @@ describe('infiniteQueryOptions', () => { it('should tag the queryKey with the result type of the QueryFn if select is used', () => { const { queryKey: tagged } = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('string'), select: (data) => data.pages, getNextPageParam: () => 1, @@ -166,7 +166,7 @@ describe('infiniteQueryOptions', () => { it('should return the proper type when passed to getQueryData', () => { const { queryKey: tagged } = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), initialPageParam: 0, queryFn: () => Promise.resolve({ page: 3 }), getNextPageParam: (lastPage) => lastPage.page + 1, @@ -180,7 +180,7 @@ describe('infiniteQueryOptions', () => { it('should properly type when passed to setQueryData', () => { const { queryKey: tagged } = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), initialPageParam: 0, queryFn: () => Promise.resolve({ page: 3 }), getNextPageParam: (lastPage) => lastPage.page + 1, @@ -212,7 +212,7 @@ describe('infiniteQueryOptions', () => { it('should not be allowed to be passed to non-infinite query functions', () => { const queryClient = new QueryClient() const options = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('string'), getNextPageParam: () => 1, initialPageParam: 1, @@ -226,7 +226,7 @@ describe('infiniteQueryOptions', () => { it('should allow optional initialData function', () => { const initialData: { example: boolean } | undefined = { example: true } const queryOptions = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => initialData, initialData: initialData ? () => ({ pages: [initialData], pageParams: [] }) @@ -244,7 +244,7 @@ describe('infiniteQueryOptions', () => { it('should allow optional initialData object', () => { const initialData: { example: boolean } | undefined = { example: true } const queryOptions = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => initialData, initialData: initialData ? { pages: [initialData], pageParams: [] } diff --git a/packages/lit-query/src/__tests__/infiniteQueryOptions.test.ts b/packages/lit-query/src/__tests__/infiniteQueryOptions.test.ts index bbf585af8bd..40d45fb0aef 100644 --- a/packages/lit-query/src/__tests__/infiniteQueryOptions.test.ts +++ b/packages/lit-query/src/__tests__/infiniteQueryOptions.test.ts @@ -1,12 +1,12 @@ import { describe, expect, it } from 'vitest' -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { infiniteQueryOptions } from '../infiniteQueryOptions.js' import type { CreateInfiniteQueryOptions } from '../createInfiniteQueryController.js' describe('infiniteQueryOptions', () => { it('should return the object received as a parameter without any modification.', () => { const object: CreateInfiniteQueryOptions = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), getNextPageParam: () => null, initialPageParam: null, diff --git a/packages/lit-query/src/__tests__/mutationOptions.test-d.ts b/packages/lit-query/src/__tests__/mutationOptions.test-d.ts index b2ad001d0b2..db5b77ec260 100644 --- a/packages/lit-query/src/__tests__/mutationOptions.test-d.ts +++ b/packages/lit-query/src/__tests__/mutationOptions.test-d.ts @@ -1,5 +1,5 @@ import { QueryClient } from '@tanstack/query-core' -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { LitElement } from 'lit' import { assertType, describe, expectTypeOf, it } from 'vitest' import { createMutationController } from '../createMutationController.js' @@ -18,7 +18,7 @@ describe('mutationOptions', () => { mutationFn: () => Promise.resolve(5), // @ts-expect-error this is a good error, because onMutates does not exist! onMutates: 1000, - mutationKey: queryKey(), + mutationKey: createKey(), onSuccess: (data) => { expectTypeOf(data).toEqualTypeOf() }, @@ -28,7 +28,7 @@ describe('mutationOptions', () => { it('should infer types for callbacks', () => { mutationOptions({ mutationFn: () => Promise.resolve(5), - mutationKey: queryKey(), + mutationKey: createKey(), onSuccess: (data) => { expectTypeOf(data).toEqualTypeOf() }, @@ -40,7 +40,7 @@ describe('mutationOptions', () => { mutationFn: () => { throw new Error('fail') }, - mutationKey: queryKey(), + mutationKey: createKey(), onError: (error) => { expectTypeOf(error).toEqualTypeOf() }, @@ -53,14 +53,14 @@ describe('mutationOptions', () => { expectTypeOf(vars).toEqualTypeOf<{ id: string }>() return Promise.resolve(5) }, - mutationKey: queryKey(), + mutationKey: createKey(), }) }) it('should infer result type correctly', () => { mutationOptions({ mutationFn: () => Promise.resolve(5), - mutationKey: queryKey(), + mutationKey: createKey(), onMutate: () => { return { name: 'onMutateResult' } }, @@ -76,7 +76,7 @@ describe('mutationOptions', () => { expectTypeOf(context).toEqualTypeOf() return Promise.resolve(5) }, - mutationKey: queryKey(), + mutationKey: createKey(), onMutate: (_variables, context) => { expectTypeOf(context).toEqualTypeOf() }, @@ -130,7 +130,7 @@ describe('mutationOptions', () => { const isMutating = useIsMutating( new Host(), mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => Promise.resolve(5), }), new QueryClient(), @@ -143,7 +143,7 @@ describe('mutationOptions', () => { const isMutating = queryClient.isMutating( mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => Promise.resolve(5), }), ) diff --git a/packages/lit-query/src/__tests__/mutationOptions.test.ts b/packages/lit-query/src/__tests__/mutationOptions.test.ts index 884afa4ad02..0c076cd37ff 100644 --- a/packages/lit-query/src/__tests__/mutationOptions.test.ts +++ b/packages/lit-query/src/__tests__/mutationOptions.test.ts @@ -1,6 +1,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { QueryClient } from '@tanstack/query-core' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { LitElement } from 'lit' import { createMutationController } from '../createMutationController.js' import { mutationOptions } from '../mutationOptions.js' @@ -45,7 +45,7 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with useIsMutating (with mutationKey in mutationOptions)', async () => { const mutationOpts = mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(10).then(() => 'data'), }) @@ -102,7 +102,7 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with useIsMutating', async () => { const mutationOpts1 = mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(10).then(() => 'data1'), }) const mutationOpts2 = mutationOptions({ @@ -140,7 +140,7 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with useIsMutating (filter mutationOpts1.mutationKey)', async () => { const mutationOpts1 = mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(10).then(() => 'data1'), }) const mutationOpts2 = mutationOptions({ @@ -182,7 +182,7 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with queryClient.isMutating (with mutationKey in mutationOptions)', async () => { const mutationOpts = mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(10).then(() => 'data'), }) @@ -233,7 +233,7 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with queryClient.isMutating', async () => { const mutationOpts1 = mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(10).then(() => 'data1'), }) const mutationOpts2 = mutationOptions({ @@ -268,7 +268,7 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with queryClient.isMutating (filter mutationOpts1.mutationKey)', async () => { const mutationOpts1 = mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(10).then(() => 'data1'), }) const mutationOpts2 = mutationOptions({ @@ -309,7 +309,7 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with useMutationState (with mutationKey in mutationOptions)', async () => { const mutationOpts = mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(10).then(() => 'data'), }) @@ -374,7 +374,7 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with useMutationState', async () => { const mutationOpts1 = mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(10).then(() => 'data1'), }) const mutationOpts2 = mutationOptions({ @@ -416,7 +416,7 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with useMutationState (filter mutationOpts1.mutationKey)', async () => { const mutationOpts1 = mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(10).then(() => 'data1'), }) const mutationOpts2 = mutationOptions({ diff --git a/packages/lit-query/src/__tests__/queryOptions.test-d.ts b/packages/lit-query/src/__tests__/queryOptions.test-d.ts index 21f0329a7ae..9729061f278 100644 --- a/packages/lit-query/src/__tests__/queryOptions.test-d.ts +++ b/packages/lit-query/src/__tests__/queryOptions.test-d.ts @@ -1,5 +1,5 @@ import { QueryClient, dataTagSymbol, skipToken } from '@tanstack/query-core' -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { LitElement } from 'lit' import { assertType, describe, expectTypeOf, it } from 'vitest' import { createQueriesController } from '../createQueriesController.js' @@ -18,7 +18,7 @@ describe('queryOptions', () => { it('should not allow excess properties', () => { assertType( queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), // @ts-expect-error this is a good error, because stallTime does not exist! stallTime: 1000, @@ -28,7 +28,7 @@ describe('queryOptions', () => { it('should infer types for callbacks', () => { queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), staleTime: 1000, select: (data) => { @@ -41,7 +41,7 @@ describe('queryOptions', () => { const query = createQueryController( new Host(), queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve({ id: 1, name: 'Ada' }), }), new QueryClient(), @@ -54,7 +54,7 @@ describe('queryOptions', () => { it('should work when passed to query', async () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }) @@ -64,7 +64,7 @@ describe('queryOptions', () => { it('should work when passed to query with select', async () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), select: (data) => data.toString(), }) @@ -75,7 +75,7 @@ describe('queryOptions', () => { it('should work when passed to query with enabled: false', async () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), enabled: false, }) @@ -86,7 +86,7 @@ describe('queryOptions', () => { it('should work when passed to query with skipToken', async () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: skipToken, }) @@ -96,7 +96,7 @@ describe('queryOptions', () => { it('should work when passed to createQueriesController', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }) @@ -112,7 +112,7 @@ describe('queryOptions', () => { it('should tag the queryKey with the result type of the QueryFn', () => { const { queryKey: tagged } = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve({ id: 2, name: 'Grace' }), }) @@ -124,7 +124,7 @@ describe('queryOptions', () => { it('should tag the queryKey even if no promise is returned', () => { const { queryKey: tagged } = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 5, }) @@ -133,7 +133,7 @@ describe('queryOptions', () => { it('should tag the queryKey with unknown if there is no queryFn', () => { const { queryKey: tagged } = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), }) expectTypeOf(tagged[dataTagSymbol]).toEqualTypeOf() @@ -141,7 +141,7 @@ describe('queryOptions', () => { it('should tag the queryKey with the result type of the QueryFn if select is used', () => { const { queryKey: tagged } = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), select: (data) => data.toString(), }) @@ -151,7 +151,7 @@ describe('queryOptions', () => { it('should return the proper type when passed to getQueryData', () => { const { queryKey: tagged } = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve({ id: 2, name: 'Grace' }), }) @@ -161,7 +161,7 @@ describe('queryOptions', () => { it('should return the proper type when passed to getQueryState', () => { const { queryKey: tagged } = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }) @@ -171,7 +171,7 @@ describe('queryOptions', () => { it('should properly type updaterFn when passed to setQueryData', () => { const { queryKey: tagged } = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }) @@ -184,7 +184,7 @@ describe('queryOptions', () => { it('should properly type value when passed to setQueryData', () => { const { queryKey: tagged } = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve({ id: 2, name: 'Grace' }), }) @@ -204,7 +204,7 @@ describe('queryOptions', () => { it('should infer even if there is a conditional skipToken', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: Math.random() > 0.5 ? skipToken : () => Promise.resolve(5), }) @@ -214,7 +214,7 @@ describe('queryOptions', () => { it('should infer to unknown if we disable a query with just a skipToken', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: skipToken, }) @@ -245,7 +245,7 @@ describe('queryOptions', () => { it('should allow optional initialData object', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('something string'), initialData: Math.random() > 0.5 ? 'initial string' : undefined, }) @@ -263,7 +263,7 @@ describe('queryOptions', () => { } const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), }) @@ -304,7 +304,7 @@ describe('queryOptions', () => { const persister = undefined as unknown as QueryPersister const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: (_context) => 'hello', persister, }) @@ -319,7 +319,7 @@ describe('queryOptions', () => { assertType( queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), // @ts-expect-error persister expects string, queryFn returns number queryFn: () => 42, persister, @@ -328,7 +328,7 @@ describe('queryOptions', () => { assertType( queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), // @ts-expect-error persister expects string, queryFn with arg returns number queryFn: (_context) => 42, persister, diff --git a/packages/lit-query/src/__tests__/ssr.test.ts b/packages/lit-query/src/__tests__/ssr.test.ts index 3934d7b1a54..77bee5b4a35 100644 --- a/packages/lit-query/src/__tests__/ssr.test.ts +++ b/packages/lit-query/src/__tests__/ssr.test.ts @@ -3,7 +3,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { render } from '@lit-labs/ssr' import { collectResult } from '@lit-labs/ssr/lib/render-result.js' import { QueryCache, QueryClient, noop } from '@tanstack/query-core' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { LitElement, html } from 'lit' import { html as staticHtml, unsafeStatic } from 'lit/static-html.js' import { createInfiniteQueryController } from '../createInfiniteQueryController.js' @@ -40,7 +40,7 @@ describe('Server Side Rendering', () => { }) it('should not trigger fetch', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => sleep(10).then(() => 'data'), ) @@ -64,7 +64,7 @@ describe('Server Side Rendering', () => { }) it('should return existing data from the cache', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => sleep(10).then(() => 'data'), ) @@ -91,7 +91,7 @@ describe('Server Side Rendering', () => { }) it('should add initialData to the cache', async () => { - const key = queryKey() + const key = createKey() class Page extends LitElement { readonly page = 1 @@ -118,7 +118,7 @@ describe('Server Side Rendering', () => { }) it('should return the correct state from createInfiniteQueryController', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => sleep(10).then(() => 'page 1'), ) @@ -158,7 +158,7 @@ describe('Server Side Rendering', () => { }) it('should return 0 from useIsFetching after prefetch completes', async () => { - const key = queryKey() + const key = createKey() const queryFn = () => sleep(10).then(() => 'data') class Page extends LitElement { @@ -186,8 +186,8 @@ describe('Server Side Rendering', () => { }) it('should return existing data from the cache with createQueriesController', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const queryFn1 = () => sleep(10).then(() => 'data1') const queryFn2 = () => sleep(10).then(() => 'data2') diff --git a/packages/lit-query/src/__tests__/useIsFetching.test.ts b/packages/lit-query/src/__tests__/useIsFetching.test.ts index b319f106ac9..2c785ec1be9 100644 --- a/packages/lit-query/src/__tests__/useIsFetching.test.ts +++ b/packages/lit-query/src/__tests__/useIsFetching.test.ts @@ -8,7 +8,7 @@ import { vi, } from 'vitest' import { QueryClient } from '@tanstack/query-core' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { LitElement, html } from 'lit' import { QueryClientProvider } from '../QueryClientProvider.js' import { createQueryController } from '../createQueryController.js' @@ -40,7 +40,7 @@ describe('useIsFetching', () => { }) it('should keep the pre-connect placeholder zero until a provider binds', async () => { - const key = queryKey() + const key = createKey() class Consumer extends LitElement { readonly queryKey = key @@ -87,7 +87,7 @@ describe('useIsFetching', () => { }) it('should prefer an explicit client over the provider context', async () => { - const key = queryKey() + const key = createKey() const providerClient = new QueryClient() const provider = document.createElement( @@ -146,7 +146,7 @@ describe('useIsFetching', () => { }) it('should track the fetching count', async () => { - const key = queryKey() + const key = createKey() class Producer extends LitElement { readonly query = createQueryController( @@ -186,7 +186,7 @@ describe('useIsFetching', () => { }) it('should not process query cache updates while disconnected', async () => { - const key = queryKey() + const key = createKey() class Producer extends LitElement { readonly query = createQueryController( @@ -228,8 +228,8 @@ describe('useIsFetching', () => { }) it('should count all fetching queries when filters are omitted', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() class Producer extends LitElement { readonly query1 = createQueryController(this, { @@ -271,8 +271,8 @@ describe('useIsFetching', () => { }) it('should be able to filter', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() class Host extends LitElement { readonly query1 = createQueryController( @@ -327,9 +327,9 @@ describe('useIsFetching', () => { }) it('should apply updated filters on host updates', async () => { - const key1 = queryKey() - const key2 = queryKey() - const unmatchedKey = queryKey() + const key1 = createKey() + const key2 = createKey() + const unmatchedKey = createKey() let activeFilter: { queryKey?: ReadonlyArray } = { queryKey: key1, } @@ -393,7 +393,7 @@ describe('useIsFetching', () => { }) it('should fail after the handshake and recover under a provider', async () => { - const key = queryKey() + const key = createKey() class Consumer extends LitElement { readonly queryKey = key @@ -438,7 +438,7 @@ describe('useIsFetching', () => { }) it('should not throw on an already-connected host with an explicit client', async () => { - const key = queryKey() + const key = createKey() class Producer extends LitElement { readonly query = createQueryController( diff --git a/packages/lit-query/src/__tests__/useIsMutating.test.ts b/packages/lit-query/src/__tests__/useIsMutating.test.ts index 7ac893d6ce5..eb816f60f2f 100644 --- a/packages/lit-query/src/__tests__/useIsMutating.test.ts +++ b/packages/lit-query/src/__tests__/useIsMutating.test.ts @@ -8,7 +8,7 @@ import { vi, } from 'vitest' import { QueryClient } from '@tanstack/query-core' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { LitElement, html } from 'lit' import { QueryClientProvider } from '../QueryClientProvider.js' import { createMutationController } from '../createMutationController.js' @@ -40,7 +40,7 @@ describe('useIsMutating', () => { }) it('should keep the pre-connect placeholder zero until a provider binds', async () => { - const mutationKey = queryKey() + const mutationKey = createKey() class Consumer extends LitElement { readonly mutationKey = mutationKey @@ -80,7 +80,7 @@ describe('useIsMutating', () => { }) it('should prefer an explicit client over the provider context', async () => { - const mutationKey = queryKey() + const mutationKey = createKey() const providerClient = new QueryClient() const provider = document.createElement( @@ -217,12 +217,12 @@ describe('useIsMutating', () => { it('should count all mutating mutations when filters are omitted', async () => { class Producer extends LitElement { readonly mutation1 = createMutationController(this, { - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(10).then(() => 'data1'), }) readonly mutation2 = createMutationController(this, { - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(10).then(() => 'data2'), }) } @@ -259,8 +259,8 @@ describe('useIsMutating', () => { }) it('should be able to filter', async () => { - const mutationKey1 = queryKey() - const mutationKey2 = queryKey() + const mutationKey1 = createKey() + const mutationKey2 = createKey() class Host extends LitElement { readonly mutationA = createMutationController( @@ -317,9 +317,9 @@ describe('useIsMutating', () => { }) it('should apply updated filters on host updates', async () => { - const mutationKey1 = queryKey() - const mutationKey2 = queryKey() - const unmatchedMutationKey = queryKey() + const mutationKey1 = createKey() + const mutationKey2 = createKey() + const unmatchedMutationKey = createKey() let activeFilter: { mutationKey?: ReadonlyArray } = { mutationKey: mutationKey1, } @@ -385,7 +385,7 @@ describe('useIsMutating', () => { }) it('should fail after the handshake and recover under a provider', async () => { - const mutationKey = queryKey() + const mutationKey = createKey() class Consumer extends LitElement { readonly mutationKey = mutationKey @@ -420,7 +420,7 @@ describe('useIsMutating', () => { }) it('should not throw on an already-connected host with an explicit client', async () => { - const mutationKey = queryKey() + const mutationKey = createKey() class Producer extends LitElement { readonly mutation = createMutationController( diff --git a/packages/lit-query/src/__tests__/useMutationState.test.ts b/packages/lit-query/src/__tests__/useMutationState.test.ts index 2ba23331084..6b9f4a12bbc 100644 --- a/packages/lit-query/src/__tests__/useMutationState.test.ts +++ b/packages/lit-query/src/__tests__/useMutationState.test.ts @@ -8,7 +8,7 @@ import { vi, } from 'vitest' import { QueryClient } from '@tanstack/query-core' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { LitElement, html } from 'lit' import { QueryClientProvider } from '../QueryClientProvider.js' import { createMutationController } from '../createMutationController.js' @@ -87,7 +87,7 @@ describe('useMutationState', () => { }) it('should not request another update when mutation cache emits with unchanged selected state', async () => { - const mutationKey = queryKey() + const mutationKey = createKey() const mutation = queryClient.getMutationCache().build(queryClient, { mutationKey, }) @@ -140,7 +140,7 @@ describe('useMutationState', () => { }) it('should keep the pre-connect placeholder empty until a provider binds', async () => { - const mutationKey = queryKey() + const mutationKey = createKey() class Consumer extends LitElement { readonly mutationKey = mutationKey @@ -180,7 +180,7 @@ describe('useMutationState', () => { }) it('should prefer an explicit client over the provider context', async () => { - const mutationKey = queryKey() + const mutationKey = createKey() const providerClient = new QueryClient() const provider = document.createElement( @@ -362,12 +362,12 @@ describe('useMutationState', () => { it('should return the states of all mutations when options are omitted', async () => { class Producer extends LitElement { readonly mutation1 = createMutationController(this, { - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(10).then(() => 'data1'), }) readonly mutation2 = createMutationController(this, { - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(10).then(() => 'data2'), }) } @@ -407,8 +407,8 @@ describe('useMutationState', () => { }) it('should select and filter by mutation key/status in useMutationState', async () => { - const mutationKey1 = queryKey() - const mutationKey2 = queryKey() + const mutationKey1 = createKey() + const mutationKey2 = createKey() let activeFilter: { mutationKey?: ReadonlyArray } = { mutationKey: mutationKey1, } @@ -474,7 +474,7 @@ describe('useMutationState', () => { }) it('should refresh useMutationState when the select closure changes on host update', async () => { - const mutationKey = queryKey() + const mutationKey = createKey() let label = 'before' class Host extends LitElement { @@ -526,7 +526,7 @@ describe('useMutationState', () => { }) it('should fail after the handshake and recover under a provider', async () => { - const mutationKey = queryKey() + const mutationKey = createKey() class Consumer extends LitElement { readonly mutationKey = mutationKey @@ -564,7 +564,7 @@ describe('useMutationState', () => { }) it('should not throw on an already-connected host with an explicit client', async () => { - const mutationKey = queryKey() + const mutationKey = createKey() class Producer extends LitElement { readonly mutation = createMutationController( diff --git a/packages/preact-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx b/packages/preact-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx index e7b6e5c0c22..b5bddb2fa72 100644 --- a/packages/preact-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx +++ b/packages/preact-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx @@ -1,6 +1,6 @@ import { act, render } from '@testing-library/preact' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { QueryClient, noop, useQuery } from '@tanstack/preact-query' import { persistQueryClientSave } from '@tanstack/query-persist-client-core' import { PersistQueryClientProvider } from '../PersistQueryClientProvider' @@ -38,7 +38,7 @@ describe('PersistQueryClientProvider (preact)', () => { }) it('should restore cache from persister and refetch', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] const queryClient = new QueryClient() diff --git a/packages/preact-query/src/__tests__/HydrationBoundary.test.tsx b/packages/preact-query/src/__tests__/HydrationBoundary.test.tsx index 40d6e67ded9..0255c0f2e4d 100644 --- a/packages/preact-query/src/__tests__/HydrationBoundary.test.tsx +++ b/packages/preact-query/src/__tests__/HydrationBoundary.test.tsx @@ -1,5 +1,5 @@ import * as coreModule from '@tanstack/query-core' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { render } from '@testing-library/preact' import { Suspense, startTransition } from 'preact/compat' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -15,9 +15,9 @@ import { import type { hydrate } from '@tanstack/query-core' describe('Preact hydration', () => { - const stringKey = queryKey() - const addedKey = queryKey() - const promiseKey = queryKey() + const stringKey = createKey() + const addedKey = createKey() + const promiseKey = createKey() let stringifiedState: string beforeEach(async () => { diff --git a/packages/preact-query/src/__tests__/QueryClientProvider.test.tsx b/packages/preact-query/src/__tests__/QueryClientProvider.test.tsx index 1a473f4e2ac..e9bab3ba8fe 100644 --- a/packages/preact-query/src/__tests__/QueryClientProvider.test.tsx +++ b/packages/preact-query/src/__tests__/QueryClientProvider.test.tsx @@ -1,4 +1,4 @@ -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { render } from '@testing-library/preact' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -20,7 +20,7 @@ describe('QueryClientProvider', () => { }) it('should set a specific cache for all queries to use', async () => { - const key = queryKey() + const key = createKey() const queryCache = new QueryCache() const queryClient = new QueryClient({ queryCache }) @@ -51,8 +51,8 @@ describe('QueryClientProvider', () => { }) it('should allow multiple caches to be partitioned', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const queryCache1 = new QueryCache() const queryCache2 = new QueryCache() @@ -107,7 +107,7 @@ describe('QueryClientProvider', () => { }) it("should use defaultOptions for queries when they don't provide their own config", async () => { - const key = queryKey() + const key = createKey() const queryCache = new QueryCache() const queryClient = new QueryClient({ diff --git a/packages/preact-query/src/__tests__/QueryResetErrorBoundary.test.tsx b/packages/preact-query/src/__tests__/QueryResetErrorBoundary.test.tsx index fba0feb2227..53565d03fbb 100644 --- a/packages/preact-query/src/__tests__/QueryResetErrorBoundary.test.tsx +++ b/packages/preact-query/src/__tests__/QueryResetErrorBoundary.test.tsx @@ -1,4 +1,4 @@ -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { fireEvent } from '@testing-library/preact' import { Suspense } from 'preact/compat' import { useEffect, useState } from 'preact/hooks' @@ -34,7 +34,7 @@ describe('QueryErrorResetBoundary', () => { describe('useQuery', () => { it('should retry fetch if the reset error boundary has been reset', async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() let succeed = false @@ -91,7 +91,7 @@ describe('QueryErrorResetBoundary', () => { it('should not throw error if query is disabled', async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() let succeed = false @@ -155,7 +155,7 @@ describe('QueryErrorResetBoundary', () => { it('should not throw error if query is disabled, and refetch if query becomes enabled again', async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() let succeed = false @@ -219,7 +219,7 @@ describe('QueryErrorResetBoundary', () => { it('should throw error if query is disabled and manually refetch', async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() function Page() { const { data, refetch, status, fetchStatus } = useQuery({ @@ -283,7 +283,7 @@ describe('QueryErrorResetBoundary', () => { it('should not retry fetch if the reset error boundary has not been reset', async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() let succeed = false @@ -340,7 +340,7 @@ describe('QueryErrorResetBoundary', () => { it('should retry fetch if the reset error boundary has been reset and the query contains data from a previous fetch', async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() let succeed = false @@ -400,7 +400,7 @@ describe('QueryErrorResetBoundary', () => { it('should not retry fetch if the reset error boundary has not been reset after a previous reset', async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() let succeed = false let shouldReset = false @@ -478,7 +478,7 @@ describe('QueryErrorResetBoundary', () => { it('should throw again on error after the reset error boundary has been reset', async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() let fetchCount = 0 function Page() { @@ -540,7 +540,7 @@ describe('QueryErrorResetBoundary', () => { it('should never render the component while the query is in error state', async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() let fetchCount = 0 let renders = 0 @@ -632,7 +632,7 @@ describe('QueryErrorResetBoundary', () => { it('should show error boundary when using tracked queries even though we do not track the error field', async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() let succeed = false @@ -691,7 +691,7 @@ describe('QueryErrorResetBoundary', () => { describe('useQueries', () => { it('should retry fetch if the reset error boundary has been reset', async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() let succeed = false @@ -752,7 +752,7 @@ describe('QueryErrorResetBoundary', () => { }) it('should retry fetch with suspense if the reset error boundary has been reset', async () => { - const key = queryKey() + const key = createKey() vi.spyOn(console, 'error').mockReturnValue(undefined) let succeed = false diff --git a/packages/preact-query/src/__tests__/fine-grained-persister.test.tsx b/packages/preact-query/src/__tests__/fine-grained-persister.test.tsx index c59cce964b0..91be796f313 100644 --- a/packages/preact-query/src/__tests__/fine-grained-persister.test.tsx +++ b/packages/preact-query/src/__tests__/fine-grained-persister.test.tsx @@ -2,7 +2,7 @@ import { PERSISTER_KEY_PREFIX, experimental_createQueryPersister, } from '@tanstack/query-persist-client-core' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { useState } from 'preact/hooks' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -25,7 +25,7 @@ describe('fine grained persister', () => { }) it('should restore query state from persister and not refetch', async () => { - const key = queryKey() + const key = createKey() const hash = hashKey(key) const spy = vi.fn<() => Promise>(() => Promise.resolve('Works from queryFn'), @@ -80,7 +80,7 @@ describe('fine grained persister', () => { }) it('should restore query state from persister and refetch', async () => { - const key = queryKey() + const key = createKey() const hash = hashKey(key) const spy = vi.fn<() => Promise>(() => sleep(5).then(() => 'Works from queryFn'), @@ -136,7 +136,7 @@ describe('fine grained persister', () => { }) it('should store query state to persister after fetch', async () => { - const key = queryKey() + const key = createKey() const hash = hashKey(key) const spy = vi.fn<() => Promise>(() => Promise.resolve('Works from queryFn'), diff --git a/packages/preact-query/src/__tests__/infiniteQueryOptions.test-d.tsx b/packages/preact-query/src/__tests__/infiniteQueryOptions.test-d.tsx index 2fb690609e6..d6f71e36741 100644 --- a/packages/preact-query/src/__tests__/infiniteQueryOptions.test-d.tsx +++ b/packages/preact-query/src/__tests__/infiniteQueryOptions.test-d.tsx @@ -1,5 +1,5 @@ import { QueryClient, dataTagSymbol, skipToken } from '@tanstack/query-core' -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { assertType, describe, expectTypeOf, it } from 'vitest' import { infiniteQueryOptions } from '../infiniteQueryOptions' @@ -25,7 +25,7 @@ describe('infiniteQueryOptions', () => { it('should not allow excess properties', () => { assertType( infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('data'), getNextPageParam: () => 1, initialPageParam: 1, @@ -37,7 +37,7 @@ describe('infiniteQueryOptions', () => { it('should infer types for callbacks', () => { infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('data'), staleTime: 1000, getNextPageParam: () => 1, @@ -50,7 +50,7 @@ describe('infiniteQueryOptions', () => { it('should work when passed to useInfiniteQuery', () => { const options = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('string'), getNextPageParam: () => 1, initialPageParam: 1, @@ -66,7 +66,7 @@ describe('infiniteQueryOptions', () => { it('should work when passed to useSuspenseInfiniteQuery', () => { const options = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('string'), getNextPageParam: () => 1, initialPageParam: 1, @@ -133,7 +133,7 @@ describe('infiniteQueryOptions', () => { it('should work when passed to fetchInfiniteQuery', async () => { const options = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('string'), getNextPageParam: () => 1, initialPageParam: 1, @@ -147,7 +147,7 @@ describe('infiniteQueryOptions', () => { it('should tag the queryKey with the result type of the QueryFn', () => { const { queryKey: tagged } = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('string'), getNextPageParam: () => 1, initialPageParam: 1, @@ -158,7 +158,7 @@ describe('infiniteQueryOptions', () => { it('should tag the queryKey even if no promise is returned', () => { const { queryKey: tagged } = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 'string', getNextPageParam: () => 1, initialPageParam: 1, @@ -169,7 +169,7 @@ describe('infiniteQueryOptions', () => { it('should tag the queryKey with the result type of the QueryFn if select is used', () => { const { queryKey: tagged } = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('string'), select: (data) => data.pages, getNextPageParam: () => 1, @@ -181,7 +181,7 @@ describe('infiniteQueryOptions', () => { it('should return the proper type when passed to getQueryData', () => { const { queryKey: tagged } = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('string'), getNextPageParam: () => 1, initialPageParam: 1, @@ -197,7 +197,7 @@ describe('infiniteQueryOptions', () => { it('should properly type when passed to setQueryData', () => { const { queryKey: tagged } = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('string'), getNextPageParam: () => 1, initialPageParam: 1, @@ -218,7 +218,7 @@ describe('infiniteQueryOptions', () => { it('should throw a type error when using queryFn with skipToken in a suspense query', () => { const options = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: Math.random() > 0.5 ? skipToken : () => Promise.resolve('string'), getNextPageParam: () => 1, @@ -232,7 +232,7 @@ describe('infiniteQueryOptions', () => { it('should not be allowed to be passed to non-infinite query functions', () => { const queryClient = new QueryClient() const options = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('string'), getNextPageParam: () => 1, initialPageParam: 1, @@ -267,7 +267,7 @@ describe('infiniteQueryOptions', () => { it('should allow optional initialData function', () => { const initialData: { example: boolean } | undefined = { example: true } const queryOptions = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => initialData, initialData: initialData ? () => ({ pages: [initialData], pageParams: [] }) @@ -285,7 +285,7 @@ describe('infiniteQueryOptions', () => { it('should allow optional initialData object', () => { const initialData: { example: boolean } | undefined = { example: true } const queryOptions = infiniteQueryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => initialData, initialData: initialData ? { pages: [initialData], pageParams: [] } diff --git a/packages/preact-query/src/__tests__/infiniteQueryOptions.test.tsx b/packages/preact-query/src/__tests__/infiniteQueryOptions.test.tsx index 4ba6cddbcb0..7d7a7971c8d 100644 --- a/packages/preact-query/src/__tests__/infiniteQueryOptions.test.tsx +++ b/packages/preact-query/src/__tests__/infiniteQueryOptions.test.tsx @@ -1,4 +1,4 @@ -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { describe, expect, it } from 'vitest' import { infiniteQueryOptions } from '../infiniteQueryOptions' @@ -6,7 +6,7 @@ import type { UseInfiniteQueryOptions } from '../types' describe('infiniteQueryOptions', () => { it('should return the object received as a parameter without any modification.', () => { - const key = queryKey() + const key = createKey() const object: UseInfiniteQueryOptions = { queryKey: key, queryFn: () => Promise.resolve(5), diff --git a/packages/preact-query/src/__tests__/mutationOptions.test-d.tsx b/packages/preact-query/src/__tests__/mutationOptions.test-d.tsx index 571619b6cda..157a1355a3a 100644 --- a/packages/preact-query/src/__tests__/mutationOptions.test-d.tsx +++ b/packages/preact-query/src/__tests__/mutationOptions.test-d.tsx @@ -1,5 +1,5 @@ import { QueryClient } from '@tanstack/query-core' -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { assertType, describe, expectTypeOf, it } from 'vitest' import { useIsMutating, useMutation, useMutationState } from '..' @@ -18,7 +18,7 @@ describe('mutationOptions', () => { mutationFn: () => Promise.resolve(5), // @ts-expect-error this is a good error, because onMutates does not exist! onMutates: 1000, - mutationKey: queryKey(), + mutationKey: createKey(), onSuccess: (data) => { expectTypeOf(data).toEqualTypeOf() }, @@ -28,7 +28,7 @@ describe('mutationOptions', () => { it('should infer types for callbacks', () => { mutationOptions({ mutationFn: () => Promise.resolve(5), - mutationKey: queryKey(), + mutationKey: createKey(), onSuccess: (data) => { expectTypeOf(data).toEqualTypeOf() }, @@ -40,7 +40,7 @@ describe('mutationOptions', () => { mutationFn: () => { throw new Error('fail') }, - mutationKey: queryKey(), + mutationKey: createKey(), onError: (error) => { expectTypeOf(error).toEqualTypeOf() }, @@ -53,14 +53,14 @@ describe('mutationOptions', () => { expectTypeOf(vars).toEqualTypeOf<{ id: string }>() return Promise.resolve(5) }, - mutationKey: queryKey(), + mutationKey: createKey(), }) }) it('should infer result type correctly', () => { mutationOptions({ mutationFn: () => Promise.resolve(5), - mutationKey: queryKey(), + mutationKey: createKey(), onMutate: () => { return { name: 'onMutateResult' } }, @@ -76,7 +76,7 @@ describe('mutationOptions', () => { expectTypeOf(context).toEqualTypeOf() return Promise.resolve(5) }, - mutationKey: queryKey(), + mutationKey: createKey(), onMutate: (_variables, context) => { expectTypeOf(context).toEqualTypeOf() }, @@ -114,7 +114,7 @@ describe('mutationOptions', () => { expectTypeOf( mutationOptions({ mutationFn: (id: string) => Promise.resolve(id.length), - mutationKey: queryKey(), + mutationKey: createKey(), onSuccess: (data) => { expectTypeOf(data).toEqualTypeOf() }, @@ -140,7 +140,7 @@ describe('mutationOptions', () => { it('should infer types when used with useMutation', () => { const mutation = useMutation( mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => Promise.resolve('data'), onSuccess: (data) => { expectTypeOf(data).toEqualTypeOf() @@ -165,7 +165,7 @@ describe('mutationOptions', () => { it('should infer types when used with useIsMutating', () => { const isMutating = useIsMutating( mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => Promise.resolve(5), }), ) @@ -184,7 +184,7 @@ describe('mutationOptions', () => { const isMutating = queryClient.isMutating( mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => Promise.resolve(5), }), ) @@ -201,7 +201,7 @@ describe('mutationOptions', () => { it('should infer types when used with useMutationState', () => { const mutationState = useMutationState({ filters: mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => Promise.resolve(5), }), }) diff --git a/packages/preact-query/src/__tests__/mutationOptions.test.tsx b/packages/preact-query/src/__tests__/mutationOptions.test.tsx index 118481b0247..6bccd48e41b 100644 --- a/packages/preact-query/src/__tests__/mutationOptions.test.tsx +++ b/packages/preact-query/src/__tests__/mutationOptions.test.tsx @@ -1,5 +1,5 @@ import { QueryClient } from '@tanstack/query-core' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { fireEvent } from '@testing-library/preact' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -37,7 +37,7 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with useIsMutating (with mutationKey in mutationOptions)', async () => { const queryClient = new QueryClient() const mutationOpts = mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(50).then(() => 'data'), }) @@ -120,7 +120,7 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with useIsMutating', async () => { const queryClient = new QueryClient() const mutationOpts1 = mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(50).then(() => 'data1'), }) const mutationOpts2 = mutationOptions({ @@ -168,7 +168,7 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with useIsMutating (filter mutationOpts1.mutationKey)', async () => { const queryClient = new QueryClient() const mutationOpts1 = mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(50).then(() => 'data1'), }) const mutationOpts2 = mutationOptions({ @@ -218,7 +218,7 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with queryClient.isMutating (with mutationKey in mutationOptions)', async () => { const isMutatingArray: Array = [] const queryClient = new QueryClient() - const key = queryKey() + const key = createKey() const mutationOpts = mutationOptions({ mutationKey: key, mutationFn: () => sleep(500).then(() => 'data'), @@ -282,7 +282,7 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with queryClient.isMutating', async () => { const isMutatingArray: Array = [] const queryClient = new QueryClient() - const key = queryKey() + const key = createKey() const mutationOpts1 = mutationOptions({ mutationKey: key, mutationFn: () => sleep(500).then(() => 'data1'), @@ -321,7 +321,7 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with queryClient.isMutating (filter mutationOpts1.mutationKey)', async () => { const isMutatingArray: Array = [] const queryClient = new QueryClient() - const key = queryKey() + const key = createKey() const mutationOpts1 = mutationOptions({ mutationKey: key, mutationFn: () => sleep(500).then(() => 'data1'), @@ -362,7 +362,7 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with useMutationState (with mutationKey in mutationOptions)', async () => { const queryClient = new QueryClient() const mutationOpts = mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(10).then(() => 'data'), }) @@ -425,7 +425,7 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with useMutationState', async () => { const queryClient = new QueryClient() const mutationOpts1 = mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(10).then(() => 'data1'), }) const mutationOpts2 = mutationOptions({ @@ -463,7 +463,7 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with useMutationState (filter mutationOpts1.mutationKey)', async () => { const queryClient = new QueryClient() const mutationOpts1 = mutationOptions({ - mutationKey: queryKey(), + mutationKey: createKey(), mutationFn: () => sleep(10).then(() => 'data1'), }) const mutationOpts2 = mutationOptions({ diff --git a/packages/preact-query/src/__tests__/queryOptions.test-d.tsx b/packages/preact-query/src/__tests__/queryOptions.test-d.tsx index d6849135ee2..8c4a462978f 100644 --- a/packages/preact-query/src/__tests__/queryOptions.test-d.tsx +++ b/packages/preact-query/src/__tests__/queryOptions.test-d.tsx @@ -1,5 +1,5 @@ import { QueryClient, dataTagSymbol, skipToken } from '@tanstack/query-core' -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { assertType, describe, expectTypeOf, it } from 'vitest' import { queryOptions } from '../queryOptions' @@ -20,7 +20,7 @@ describe('queryOptions', () => { it('should not allow excess properties', () => { assertType( queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), // @ts-expect-error this is a good error, because stallTime does not exist! stallTime: 1000, @@ -30,7 +30,7 @@ describe('queryOptions', () => { it('should infer types for callbacks', () => { queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), staleTime: 1000, select: (data) => { @@ -41,7 +41,7 @@ describe('queryOptions', () => { it('should work when passed to useQuery', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }) @@ -51,7 +51,7 @@ describe('queryOptions', () => { it('should work when passed to useSuspenseQuery', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }) @@ -103,7 +103,7 @@ describe('queryOptions', () => { it('should work when passed to fetchQuery', async () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }) @@ -114,7 +114,7 @@ describe('queryOptions', () => { it('should work when passed to useQueries', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }) @@ -127,7 +127,7 @@ describe('queryOptions', () => { it('should tag the queryKey with the result type of the QueryFn', () => { const { queryKey: tagged } = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }) @@ -136,7 +136,7 @@ describe('queryOptions', () => { it('should tag the queryKey even if no promise is returned', () => { const { queryKey: tagged } = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 5, }) @@ -145,7 +145,7 @@ describe('queryOptions', () => { it('should tag the queryKey with unknown if there is no queryFn', () => { const { queryKey: tagged } = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), }) expectTypeOf(tagged[dataTagSymbol]).toEqualTypeOf() @@ -153,7 +153,7 @@ describe('queryOptions', () => { it('should tag the queryKey with the result type of the QueryFn if select is used', () => { const { queryKey: tagged } = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), select: (data) => data.toString(), }) @@ -163,7 +163,7 @@ describe('queryOptions', () => { it('should return the proper type when passed to getQueryData', () => { const { queryKey: tagged } = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }) @@ -174,7 +174,7 @@ describe('queryOptions', () => { it('should return the proper type when passed to getQueryState', () => { const { queryKey: tagged } = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }) @@ -185,7 +185,7 @@ describe('queryOptions', () => { it('should properly type updaterFn when passed to setQueryData', () => { const { queryKey: tagged } = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }) @@ -199,7 +199,7 @@ describe('queryOptions', () => { it('should properly type value when passed to setQueryData', () => { const { queryKey: tagged } = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }) @@ -216,7 +216,7 @@ describe('queryOptions', () => { it('should infer even if there is a conditional skipToken', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: Math.random() > 0.5 ? skipToken : () => Promise.resolve(5), }) @@ -227,7 +227,7 @@ describe('queryOptions', () => { it('should infer to unknown if we disable a query with just a skipToken', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: skipToken, }) @@ -239,7 +239,7 @@ describe('queryOptions', () => { it('should throw a type error when using queryFn with skipToken in a suspense query', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: Math.random() > 0.5 ? skipToken : () => Promise.resolve(5), }) // @ts-expect-error TS2345 @@ -250,7 +250,7 @@ describe('queryOptions', () => { it('should allow undefined response in initialData', () => { assertType((id: string | null) => queryOptions({ - queryKey: [...queryKey(), id], + queryKey: [...createKey(), id], queryFn: () => Promise.resolve({ id: '1', @@ -269,7 +269,7 @@ describe('queryOptions', () => { it('should allow optional initialData object', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('something string'), initialData: Math.random() > 0.5 ? 'initial string' : undefined, }) @@ -287,7 +287,7 @@ describe('queryOptions', () => { } const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), }) diff --git a/packages/preact-query/src/__tests__/ssr-hydration.test.tsx b/packages/preact-query/src/__tests__/ssr-hydration.test.tsx index 9540fd1940b..5acfd2e4ee3 100644 --- a/packages/preact-query/src/__tests__/ssr-hydration.test.tsx +++ b/packages/preact-query/src/__tests__/ssr-hydration.test.tsx @@ -1,4 +1,4 @@ -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { act } from '@testing-library/preact' import { hydrate as preactHydrate, render } from 'preact' import { renderToString } from 'preact-render-to-string' @@ -38,8 +38,8 @@ function PrintStateComponent({ componentName, result }: any): any { } describe('Server side rendering with de/rehydration', () => { - const successKey = queryKey() - const errorKey = queryKey() + const successKey = createKey() + const errorKey = createKey() beforeAll(() => { vi.useFakeTimers() diff --git a/packages/preact-query/src/__tests__/ssr.test.tsx b/packages/preact-query/src/__tests__/ssr.test.tsx index 0bddc39a6f2..869a9812c0a 100644 --- a/packages/preact-query/src/__tests__/ssr.test.tsx +++ b/packages/preact-query/src/__tests__/ssr.test.tsx @@ -1,4 +1,4 @@ -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { renderToString } from 'preact-render-to-string' import { useState } from 'preact/hooks' import { @@ -48,7 +48,7 @@ describe('Server Side Rendering', () => { }) it('should not trigger fetch', () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => sleep(10).then(() => 'data'), ) @@ -76,7 +76,7 @@ describe('Server Side Rendering', () => { }) it('should add prefetched data to cache', async () => { - const key = queryKey() + const key = createKey() const promise = queryClient.query({ queryKey: key, @@ -91,7 +91,7 @@ describe('Server Side Rendering', () => { }) it('should return existing data from the cache', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => sleep(10).then(() => 'data'), ) @@ -122,7 +122,7 @@ describe('Server Side Rendering', () => { }) it('should add initialData to the cache', () => { - const key = queryKey() + const key = createKey() function Page() { const [page, setPage] = useState(1) @@ -168,7 +168,7 @@ describe('Server Side Rendering', () => { }) it('should return the correct state from useInfiniteQuery', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => sleep(10).then(() => 'page 1'), ) diff --git a/packages/preact-query/src/__tests__/suspense.test.tsx b/packages/preact-query/src/__tests__/suspense.test.tsx index 155beb48e7c..46080aca858 100644 --- a/packages/preact-query/src/__tests__/suspense.test.tsx +++ b/packages/preact-query/src/__tests__/suspense.test.tsx @@ -1,4 +1,4 @@ -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { render } from '@testing-library/preact' import { Suspense } from 'preact/compat' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -59,7 +59,7 @@ describe('Suspense Timer Tests', () => { it('should enforce minimum staleTime of 1000ms when using suspense with number', async () => { const TestComponent = createTestQuery({ fetchCount, - queryKey: queryKey(), + queryKey: createKey(), staleTime: 10, }) @@ -84,7 +84,7 @@ describe('Suspense Timer Tests', () => { it('should enforce minimum staleTime of 1000ms when using suspense with function', async () => { const TestComponent = createTestQuery({ fetchCount, - queryKey: queryKey(), + queryKey: createKey(), staleTime: () => 10, }) @@ -109,7 +109,7 @@ describe('Suspense Timer Tests', () => { it('should respect staleTime when value is greater than 1000ms', async () => { const TestComponent = createTestQuery({ fetchCount, - queryKey: queryKey(), + queryKey: createKey(), staleTime: 2000, }) @@ -134,7 +134,7 @@ describe('Suspense Timer Tests', () => { it('should enforce minimum staleTime when undefined is provided', async () => { const TestComponent = createTestQuery({ fetchCount, - queryKey: queryKey(), + queryKey: createKey(), staleTime: undefined, }) @@ -159,7 +159,7 @@ describe('Suspense Timer Tests', () => { it('should preserve staleTime when value is static', async () => { const TestComponent = createTestQuery({ fetchCount, - queryKey: queryKey(), + queryKey: createKey(), staleTime: 'static', }) @@ -184,7 +184,7 @@ describe('Suspense Timer Tests', () => { it('should preserve staleTime when function returns static', async () => { const TestComponent = createTestQuery({ fetchCount, - queryKey: queryKey(), + queryKey: createKey(), staleTime: () => 'static', }) @@ -209,7 +209,7 @@ describe('Suspense Timer Tests', () => { it('should respect staleTime when function returns value greater than 1000ms', async () => { const TestComponent = createTestQuery({ fetchCount, - queryKey: queryKey(), + queryKey: createKey(), staleTime: () => 3000, }) diff --git a/packages/preact-query/src/__tests__/useInfiniteQuery.test-d.tsx b/packages/preact-query/src/__tests__/useInfiniteQuery.test-d.tsx index 76208572dd4..81143b59aa1 100644 --- a/packages/preact-query/src/__tests__/useInfiniteQuery.test-d.tsx +++ b/packages/preact-query/src/__tests__/useInfiniteQuery.test-d.tsx @@ -1,5 +1,5 @@ import { QueryClient } from '@tanstack/query-core' -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { describe, expectTypeOf, it } from 'vitest' import { useInfiniteQuery } from '../useInfiniteQuery' @@ -9,7 +9,7 @@ import type { InfiniteData } from '@tanstack/query-core' describe('pageParam', () => { it('should define type of param passed to queryFunctionContext with initialPageParam', () => { useInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: ({ pageParam }) => { expectTypeOf(pageParam).toEqualTypeOf() }, @@ -20,7 +20,7 @@ describe('pageParam', () => { it('should pass direction to queryFn of useInfiniteQuery', () => { useInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: ({ direction }) => { expectTypeOf(direction).toEqualTypeOf<'forward' | 'backward'>() }, @@ -33,7 +33,7 @@ describe('pageParam', () => { const queryClient = new QueryClient() // oxlint-disable-next-line tanstack-query/no-restricted-syntax -- grandfathered direct test queryClient.fetchInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: ({ pageParam }) => { expectTypeOf(pageParam).toEqualTypeOf() }, @@ -57,7 +57,7 @@ describe('pageParam', () => { const queryClient = new QueryClient() // oxlint-disable-next-line tanstack-query/no-restricted-syntax -- grandfathered direct test queryClient.prefetchInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: ({ pageParam }) => { expectTypeOf(pageParam).toEqualTypeOf() }, @@ -69,7 +69,7 @@ describe('pageParam', () => { describe('select', () => { it('should still return paginated data if no select result', () => { const infiniteQuery = useInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: ({ pageParam }) => { return pageParam * 5 }, @@ -85,7 +85,7 @@ describe('select', () => { it('should be able to transform data to arbitrary result', () => { const infiniteQuery = useInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: ({ pageParam }) => { return pageParam * 5 }, @@ -104,7 +104,7 @@ describe('select', () => { describe('getNextPageParam / getPreviousPageParam', () => { it('should get typed params', () => { const infiniteQuery = useInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: ({ pageParam }) => { return String(pageParam) }, @@ -145,7 +145,7 @@ describe('error booleans', () => { isLoadingError, isRefetchError, } = useInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: ({ pageParam }) => { return pageParam * 5 }, @@ -163,7 +163,7 @@ describe('error booleans', () => { describe('UseInfiniteQueryOptions', () => { it('should default TData to InfiniteData', () => { const options: UseInfiniteQueryOptions = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 5, initialPageParam: 1, getNextPageParam: () => undefined, diff --git a/packages/preact-query/src/__tests__/useInfiniteQuery.test.tsx b/packages/preact-query/src/__tests__/useInfiniteQuery.test.tsx index dcad0ae09a5..08f6f674289 100644 --- a/packages/preact-query/src/__tests__/useInfiniteQuery.test.tsx +++ b/packages/preact-query/src/__tests__/useInfiniteQuery.test.tsx @@ -1,4 +1,4 @@ -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { fireEvent, render } from '@testing-library/preact' import { useCallback, useEffect, useRef, useState } from 'preact/hooks' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -48,7 +48,7 @@ describe('useInfiniteQuery', () => { }) it('should return the correct states for a successful query', async () => { - const key = queryKey() + const key = createKey() const states: Array>> = [] function Page() { @@ -139,7 +139,7 @@ describe('useInfiniteQuery', () => { }) it('should not throw when fetchNextPage returns an error', async () => { - const key = queryKey() + const key = createKey() let noThrow = false function Page() { @@ -179,7 +179,7 @@ describe('useInfiniteQuery', () => { }) it('should keep the previous data when placeholderData is set', async () => { - const key = queryKey() + const key = createKey() const states: Array>> = [] function Page() { @@ -268,7 +268,7 @@ describe('useInfiniteQuery', () => { }) it('should be able to select a part of the data', async () => { - const key = queryKey() + const key = createKey() const states: Array>> = [] function Page() { @@ -304,7 +304,7 @@ describe('useInfiniteQuery', () => { }) it('should be able to select a new result and not cause infinite renders', async () => { - const key = queryKey() + const key = createKey() const states: Array< UseInfiniteQueryResult> > = [] @@ -353,7 +353,7 @@ describe('useInfiniteQuery', () => { }) it('should be able to reverse the data', async () => { - const key = queryKey() + const key = createKey() const states: Array>> = [] function Page() { @@ -409,7 +409,7 @@ describe('useInfiniteQuery', () => { }) it('should be able to fetch a previous page', async () => { - const key = queryKey() + const key = createKey() const states: Array>> = [] function Page() { @@ -486,7 +486,7 @@ describe('useInfiniteQuery', () => { }) it('should be able to refetch when providing page params automatically', async () => { - const key = queryKey() + const key = createKey() const states: Array>> = [] function Page() { @@ -596,7 +596,7 @@ describe('useInfiniteQuery', () => { }) it('should return the correct states when refetch fails', async () => { - const key = queryKey() + const key = createKey() const states: Array>> = [] let isRefetch = false @@ -689,7 +689,7 @@ describe('useInfiniteQuery', () => { }) it('should return the correct states when fetchNextPage fails', async () => { - const key = queryKey() + const key = createKey() const states: Array>> = [] function Page() { @@ -774,7 +774,7 @@ describe('useInfiniteQuery', () => { }) it('should return the correct states when fetchPreviousPage fails', async () => { - const key = queryKey() + const key = createKey() const states: Array>> = [] function Page() { @@ -863,7 +863,7 @@ describe('useInfiniteQuery', () => { }) it('should silently cancel any ongoing fetch when fetching more', async () => { - const key = queryKey() + const key = createKey() function Page() { const start = 10 @@ -908,7 +908,7 @@ describe('useInfiniteQuery', () => { }) it('should silently cancel an ongoing fetchNextPage request when another fetchNextPage is invoked', async () => { - const key = queryKey() + const key = createKey() const start = 10 const onAborts: Array) => any>> = [] const abortListeners: Array) => any>> = [] @@ -983,7 +983,7 @@ describe('useInfiniteQuery', () => { }) it('should not cancel an ongoing fetchNextPage request when another fetchNextPage is invoked if `cancelRefetch: false` is used', async () => { - const key = queryKey() + const key = createKey() const start = 10 const onAborts: Array) => any>> = [] const abortListeners: Array) => any>> = [] @@ -1049,7 +1049,7 @@ describe('useInfiniteQuery', () => { }) it('should keep fetching first page when not loaded yet and triggering fetch more', async () => { - const key = queryKey() + const key = createKey() const states: Array>> = [] function Page() { @@ -1096,7 +1096,7 @@ describe('useInfiniteQuery', () => { }) it('should stop fetching additional pages when the component is unmounted and AbortSignal is consumed', async () => { - const key = queryKey() + const key = createKey() let fetches = 0 const initialData = { pages: [1, 2, 3, 4], pageParams: [0, 1, 2, 3] } @@ -1143,7 +1143,7 @@ describe('useInfiniteQuery', () => { }) it('should be able to set new pages with the query client', async () => { - const key = queryKey() + const key = createKey() let multiplier = 1 @@ -1200,7 +1200,7 @@ describe('useInfiniteQuery', () => { }) it('should keep initialData visible alongside the error when a refetch fails', async () => { - const key = queryKey() + const key = createKey() const states: Array>> = [] function Page() { @@ -1234,7 +1234,7 @@ describe('useInfiniteQuery', () => { }) it('should set hasNextPage to false if getNextPageParam returns undefined', async () => { - const key = queryKey() + const key = createKey() const states: Array>> = [] function Page() { @@ -1271,7 +1271,7 @@ describe('useInfiniteQuery', () => { }) it('should compute hasNextPage correctly using initialData', async () => { - const key = queryKey() + const key = createKey() const states: Array>> = [] function Page() { @@ -1309,7 +1309,7 @@ describe('useInfiniteQuery', () => { }) it('should compute hasNextPage correctly for falsy getFetchMore return value using initialData', async () => { - const key = queryKey() + const key = createKey() const states: Array>> = [] function Page() { @@ -1347,7 +1347,7 @@ describe('useInfiniteQuery', () => { }) it('should not use selected data when computing hasNextPage', async () => { - const key = queryKey() + const key = createKey() const states: Array>> = [] function Page() { @@ -1388,7 +1388,7 @@ describe('useInfiniteQuery', () => { }) it('should build fresh cursors on refetch', async () => { - const key = queryKey() + const key = createKey() const genItems = (size: number) => [...new Array(size)].fill(null).map((_, d) => d) @@ -1523,7 +1523,7 @@ describe('useInfiniteQuery', () => { }) it('should compute hasNextPage correctly for falsy getFetchMore return value on refetching', async () => { - const key = queryKey() + const key = createKey() const MAX = 2 function Page() { @@ -1643,7 +1643,7 @@ describe('useInfiniteQuery', () => { }) it('should cancel the query function when there are no more subscriptions', () => { - const key = queryKey() + const key = createKey() let cancelFn: Mock = vi.fn<(event: Event) => void>() const queryFn = ({ signal }: { signal?: AbortSignal }) => { @@ -1695,7 +1695,7 @@ describe('useInfiniteQuery', () => { }) it('should use provided custom queryClient', async () => { - const key = queryKey() + const key = createKey() const queryFn = () => sleep(10).then(() => 'custom client') function Page() { @@ -1719,7 +1719,7 @@ describe('useInfiniteQuery', () => { }) it('should not fetch when queryFn is skipToken, and fetch once it is replaced', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<(context: { pageParam: number }) => Promise>( ({ pageParam }: { pageParam: number }) => sleep(10).then(() => `comments for 1 page ${pageParam}`), diff --git a/packages/preact-query/src/__tests__/useIsFetching.test.tsx b/packages/preact-query/src/__tests__/useIsFetching.test.tsx index b2d4046fcc4..3359f0cc5ad 100644 --- a/packages/preact-query/src/__tests__/useIsFetching.test.tsx +++ b/packages/preact-query/src/__tests__/useIsFetching.test.tsx @@ -1,4 +1,4 @@ -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { fireEvent, render } from '@testing-library/preact' import { useEffect, useState } from 'preact/hooks' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -19,7 +19,7 @@ describe('useIsFetching', () => { // See https://github.com/tannerlinsley/react-query/issues/105 it('should update as queries start and stop fetching', async () => { const queryClient = new QueryClient() - const key = queryKey() + const key = createKey() function IsFetching() { const isFetching = useIsFetching() @@ -62,8 +62,8 @@ describe('useIsFetching', () => { it('should not update state while rendering', async () => { const queryClient = new QueryClient() - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const isFetchingArray: Array = [] @@ -130,8 +130,8 @@ describe('useIsFetching', () => { it('should be able to filter', async () => { const queryClient = new QueryClient() - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const isFetchingArray: Array = [] @@ -189,7 +189,7 @@ describe('useIsFetching', () => { it('should show the correct fetching state when mounted after a query', async () => { const queryClient = new QueryClient() - const key = queryKey() + const key = createKey() function Page() { useQuery({ @@ -219,7 +219,7 @@ describe('useIsFetching', () => { const queryCache = new QueryCache({ onSuccess }) const queryClient = new QueryClient({ queryCache }) - const key = queryKey() + const key = createKey() function Page() { useQuery( diff --git a/packages/preact-query/src/__tests__/useMutation.test.tsx b/packages/preact-query/src/__tests__/useMutation.test.tsx index ccc82017e01..b9014e6f629 100644 --- a/packages/preact-query/src/__tests__/useMutation.test.tsx +++ b/packages/preact-query/src/__tests__/useMutation.test.tsx @@ -1,4 +1,4 @@ -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { fireEvent, render } from '@testing-library/preact' import { useEffect, useState } from 'preact/hooks' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -982,7 +982,7 @@ describe('useMutation', () => { }) it('should be able to use mutation defaults', async () => { - const key = queryKey() + const key = createKey() queryClient.setMutationDefaults(key, { mutationFn: (text: string) => sleep(10).then(() => text), @@ -1207,7 +1207,7 @@ describe('useMutation', () => { it('should be able to retry a mutation when online', async () => { const onlineMock = mockOnlineManagerIsOnline(false) - const key = queryKey() + const key = createKey() let count = 0 @@ -1573,7 +1573,7 @@ describe('useMutation', () => { context: MutationFunctionContext, ) => void >() - const mutationKey = queryKey() + const mutationKey = createKey() let count = 0 function Page() { @@ -2295,7 +2295,7 @@ describe('useMutation', () => { }) it('should update the cache in onMutate and roll back via onMutateResult in onError', async () => { - const key = queryKey() + const key = createKey() queryClient.setQueryData>(key, ['Todo 1']) function Page() { @@ -2333,7 +2333,7 @@ describe('useMutation', () => { }) it('should keep the optimistic update in place when the mutation succeeds', async () => { - const key = queryKey() + const key = createKey() queryClient.setQueryData>(key, ['Todo 1']) function Page() { @@ -2535,7 +2535,7 @@ describe('useMutation', () => { }) it('should give mutationFn the same QueryClient instance via context', async () => { - const key = queryKey() + const key = createKey() queryClient.setQueryData(key, 'tag-from-this-client') function Page() { @@ -2592,7 +2592,7 @@ describe('useMutation', () => { }) it('should let onSuccess invalidate queries via context.client without a useQueryClient() closure', async () => { - const key = queryKey() + const key = createKey() queryClient.setQueryData(key, 'data') function Page() { diff --git a/packages/preact-query/src/__tests__/useMutationState.test.tsx b/packages/preact-query/src/__tests__/useMutationState.test.tsx index fc492d20e9a..87d7a804b31 100644 --- a/packages/preact-query/src/__tests__/useMutationState.test.tsx +++ b/packages/preact-query/src/__tests__/useMutationState.test.tsx @@ -1,7 +1,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { fireEvent, render } from '@testing-library/preact' import { useEffect } from 'preact/hooks' -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { QueryClient, useIsMutating, useMutation, useMutationState } from '..' import { renderWithClient } from './utils' import type { Mutation, MutationCacheNotifyEvent } from '..' @@ -17,8 +17,8 @@ describe('useIsMutating', () => { it('should return the number of fetching mutations', async () => { const queryClient = new QueryClient() - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() function IsMutating() { const isMutating = useIsMutating() @@ -103,8 +103,8 @@ describe('useIsMutating', () => { it('should filter correctly by mutationKey', async () => { const queryClient = new QueryClient() - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() function IsMutating() { const isMutating = useIsMutating({ mutationKey: key1 }) @@ -141,8 +141,8 @@ describe('useIsMutating', () => { it('should filter correctly by predicate', async () => { const queryClient = new QueryClient() - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() function IsMutating() { const isMutating = useIsMutating({ @@ -181,7 +181,7 @@ describe('useIsMutating', () => { it('should use provided custom queryClient', async () => { const queryClient = new QueryClient() - const key = queryKey() + const key = createKey() function Page() { const isMutating = useIsMutating({}, queryClient) @@ -212,8 +212,8 @@ describe('useIsMutating', () => { it('should update when filters change without a cache update', async () => { const queryClient = new QueryClient() - const key = queryKey() - const otherKey = queryKey() + const key = createKey() + const otherKey = createKey() const mutation = queryClient.getMutationCache().build(queryClient, { mutationKey: key, mutationFn: () => sleep(100), @@ -248,8 +248,8 @@ describe('useMutationState', () => { it('should update when filters change without a cache update', () => { const queryClient = new QueryClient() - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const cache = queryClient.getMutationCache() cache.build(queryClient, { mutationKey: key1 }) cache.build(queryClient, { mutationKey: key2 }) @@ -274,7 +274,7 @@ describe('useMutationState', () => { rendered.getByText(`keys: ${JSON.stringify([key2])}`), ).toBeInTheDocument() - rendered.rerender() + rendered.rerender() expect(rendered.getByText('keys: []')).toBeInTheDocument() expect(onCacheChange).not.toHaveBeenCalled() unsubscribe() @@ -282,7 +282,7 @@ describe('useMutationState', () => { it('should update when select changes without a cache update', () => { const queryClient = new QueryClient() - const key = queryKey() + const key = createKey() queryClient.getMutationCache().build(queryClient, { mutationKey: key }) function Page({ select }: { select: (mutation: Mutation) => unknown }) { @@ -306,7 +306,7 @@ describe('useMutationState', () => { 'should recompute %s results on rerender with stable filters and select', (resultType) => { const queryClient = new QueryClient() - const key = queryKey() + const key = createKey() const cache = queryClient.getMutationCache() const mutation = cache.build(queryClient, { mutationKey: key, @@ -353,7 +353,7 @@ describe('useMutationState', () => { it('should render selector results that cannot be structurally shared', () => { const queryClient = new QueryClient() - const key = queryKey() + const key = createKey() queryClient.getMutationCache().build(queryClient, { mutationKey: key }) function Page({ time }: { time: number }) { @@ -378,7 +378,7 @@ describe('useMutationState', () => { it('should update Date selector results when mutation state changes', async () => { const queryClient = new QueryClient() - const key = queryKey() + const key = createKey() const filters = { mutationKey: key } const select = (mutation: Mutation) => new Date(mutation.state.status === 'success' ? 1000 : 0) @@ -414,7 +414,7 @@ describe('useMutationState', () => { it('should update when only the mutation state changes', async () => { const queryClient = new QueryClient() - const key = queryKey() + const key = createKey() const filters = { mutationKey: key } const select = (mutation: Mutation) => mutation.state.status @@ -452,7 +452,7 @@ describe('useMutationState', () => { 'should preserve the result reference with %s inputs', (inputs) => { const queryClient = new QueryClient() - const key = queryKey() + const key = createKey() queryClient.getMutationCache().build(queryClient, { mutationKey: key }) const onResult = vi.fn< @@ -488,8 +488,8 @@ describe('useMutationState', () => { it('should read from a changed custom queryClient', () => { const client1 = new QueryClient() const client2 = new QueryClient() - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() client1.getMutationCache().build(client1, { mutationKey: key1 }) client2.getMutationCache().build(client2, { mutationKey: key2 }) const select = (mutation: Mutation) => mutation.options.mutationKey diff --git a/packages/preact-query/src/__tests__/usePrefetchInfiniteQuery.test-d.tsx b/packages/preact-query/src/__tests__/usePrefetchInfiniteQuery.test-d.tsx index 2c160bcb6c4..6558936fb04 100644 --- a/packages/preact-query/src/__tests__/usePrefetchInfiniteQuery.test-d.tsx +++ b/packages/preact-query/src/__tests__/usePrefetchInfiniteQuery.test-d.tsx @@ -1,4 +1,4 @@ -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { assertType, describe, expectTypeOf, it } from 'vitest' import { skipToken, usePrefetchInfiniteQuery } from '..' @@ -6,7 +6,7 @@ import { skipToken, usePrefetchInfiniteQuery } from '..' describe('usePrefetchInfiniteQuery', () => { it('should return nothing', () => { const result = usePrefetchInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), initialPageParam: 1, getNextPageParam: () => 1, @@ -19,7 +19,7 @@ describe('usePrefetchInfiniteQuery', () => { assertType( // @ts-expect-error TS2345 usePrefetchInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }), ) @@ -28,7 +28,7 @@ describe('usePrefetchInfiniteQuery', () => { it('should not allow refetchInterval, enabled or throwOnError options', () => { assertType( usePrefetchInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), initialPageParam: 1, getNextPageParam: () => 1, @@ -39,7 +39,7 @@ describe('usePrefetchInfiniteQuery', () => { assertType( usePrefetchInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), initialPageParam: 1, getNextPageParam: () => 1, @@ -50,7 +50,7 @@ describe('usePrefetchInfiniteQuery', () => { assertType( usePrefetchInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), initialPageParam: 1, getNextPageParam: () => 1, @@ -63,7 +63,7 @@ describe('usePrefetchInfiniteQuery', () => { it('should not allow skipToken in queryFn', () => { assertType( usePrefetchInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), // @ts-expect-error queryFn: skipToken, initialPageParam: 1, @@ -72,7 +72,7 @@ describe('usePrefetchInfiniteQuery', () => { ) assertType( usePrefetchInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), // @ts-expect-error queryFn: Math.random() > 0.5 ? skipToken : () => Promise.resolve(5), initialPageParam: 1, diff --git a/packages/preact-query/src/__tests__/usePrefetchInfiniteQuery.test.tsx b/packages/preact-query/src/__tests__/usePrefetchInfiniteQuery.test.tsx index ae968799f29..2ccbde43671 100644 --- a/packages/preact-query/src/__tests__/usePrefetchInfiniteQuery.test.tsx +++ b/packages/preact-query/src/__tests__/usePrefetchInfiniteQuery.test.tsx @@ -1,4 +1,4 @@ -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { fireEvent } from '@testing-library/preact' import { Suspense } from 'preact/compat' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -41,7 +41,7 @@ describe('usePrefetchInfiniteQuery', () => { ] const queryOpts = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: vi .fn<(context: { pageParam: number }) => Promise>() .mockImplementation(({ pageParam }) => @@ -101,7 +101,7 @@ describe('usePrefetchInfiniteQuery', () => { ] const queryOpts = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: vi .fn<(context: { pageParam: number }) => Promise>() .mockImplementation(({ pageParam }) => @@ -156,7 +156,7 @@ describe('usePrefetchInfiniteQuery', () => { const data = ['Infinite Page 1', 'Infinite Page 2', 'Infinite Page 3'] const queryOpts = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: vi .fn<(context: { pageParam: number }) => Promise>() .mockImplementation(({ pageParam }) => diff --git a/packages/preact-query/src/__tests__/usePrefetchQuery.test-d.tsx b/packages/preact-query/src/__tests__/usePrefetchQuery.test-d.tsx index b50a0af1b06..34ef07935c2 100644 --- a/packages/preact-query/src/__tests__/usePrefetchQuery.test-d.tsx +++ b/packages/preact-query/src/__tests__/usePrefetchQuery.test-d.tsx @@ -1,4 +1,4 @@ -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { assertType, describe, expectTypeOf, it } from 'vitest' import { skipToken, usePrefetchQuery } from '..' @@ -6,7 +6,7 @@ import { skipToken, usePrefetchQuery } from '..' describe('usePrefetchQuery', () => { it('should return nothing', () => { const result = usePrefetchQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }) @@ -32,7 +32,7 @@ describe('usePrefetchQuery', () => { it('should not allow refetchInterval, enabled or throwOnError options', () => { assertType( usePrefetchQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), // @ts-expect-error TS2345 refetchInterval: 1000, @@ -41,7 +41,7 @@ describe('usePrefetchQuery', () => { assertType( usePrefetchQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), // @ts-expect-error TS2345 enabled: true, @@ -50,7 +50,7 @@ describe('usePrefetchQuery', () => { assertType( usePrefetchQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), // @ts-expect-error TS2345 throwOnError: true, @@ -61,14 +61,14 @@ describe('usePrefetchQuery', () => { it('should not allow skipToken in queryFn', () => { assertType( usePrefetchQuery({ - queryKey: queryKey(), + queryKey: createKey(), // @ts-expect-error queryFn: skipToken, }), ) assertType( usePrefetchQuery({ - queryKey: queryKey(), + queryKey: createKey(), // @ts-expect-error queryFn: Math.random() > 0.5 ? skipToken : () => Promise.resolve(5), }), diff --git a/packages/preact-query/src/__tests__/usePrefetchQuery.test.tsx b/packages/preact-query/src/__tests__/usePrefetchQuery.test.tsx index f7aee69eaa2..9a25977fb9d 100644 --- a/packages/preact-query/src/__tests__/usePrefetchQuery.test.tsx +++ b/packages/preact-query/src/__tests__/usePrefetchQuery.test.tsx @@ -1,4 +1,4 @@ -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { act, fireEvent } from '@testing-library/preact' import { Suspense } from 'preact/compat' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -32,7 +32,7 @@ describe('usePrefetchQuery', () => { it('should prefetch query if query state does not exist', async () => { const queryOpts = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: vi.fn<() => Promise>(() => sleep(10).then(() => 'prefetchQuery'), ), @@ -68,7 +68,7 @@ describe('usePrefetchQuery', () => { it('should not prefetch query if query state exists', async () => { const queryOpts = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: vi.fn<() => Promise>(() => sleep(10).then(() => 'The usePrefetchQuery hook is smart!'), ), @@ -109,7 +109,7 @@ describe('usePrefetchQuery', () => { ) const queryOpts = { - queryKey: queryKey(), + queryKey: createKey(), queryFn, } @@ -153,7 +153,7 @@ describe('usePrefetchQuery', () => { ) const queryOpts = { - queryKey: queryKey(), + queryKey: createKey(), queryFn, } @@ -192,7 +192,7 @@ describe('usePrefetchQuery', () => { ) const queryOpts = { - queryKey: queryKey(), + queryKey: createKey(), queryFn, } @@ -247,21 +247,21 @@ describe('usePrefetchQuery', () => { it('should not create a suspense waterfall if prefetch is fired', async () => { const firstQueryOpts = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: vi.fn<() => Promise>(() => sleep(10).then(() => 'Prefetch is nice!'), ), } const secondQueryOpts = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: vi.fn<() => Promise>(() => sleep(10).then(() => 'Prefetch is really nice!!'), ), } const thirdQueryOpts = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: vi.fn<() => Promise>(() => sleep(10).then(() => 'Prefetch does not create waterfalls!!'), ), diff --git a/packages/preact-query/src/__tests__/useQueries.test-d.tsx b/packages/preact-query/src/__tests__/useQueries.test-d.tsx index 6aa5d9f6079..45c6052ed98 100644 --- a/packages/preact-query/src/__tests__/useQueries.test-d.tsx +++ b/packages/preact-query/src/__tests__/useQueries.test-d.tsx @@ -1,4 +1,4 @@ -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { describe, expectTypeOf, it } from 'vitest' import { skipToken } from '..' @@ -12,7 +12,7 @@ describe('useQueries', () => { describe('config object overload', () => { it('should always define TData when initialData is provided as an object', () => { const query1 = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => { return { wow: true, @@ -24,13 +24,13 @@ describe('useQueries', () => { } const query2 = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 'Query Data', initialData: 'initial data', } const query3 = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 'Query Data', } @@ -47,7 +47,7 @@ describe('useQueries', () => { it('should define TData when passed through queryOptions', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => { return { wow: true, @@ -66,13 +66,13 @@ describe('useQueries', () => { it('should be possible to define a different TData than TQueryFnData using select with queryOptions spread into useQueries', () => { const query1 = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), select: (data) => data > 1, }) const query2 = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), select: (data: number) => data > 1, } @@ -89,7 +89,7 @@ describe('useQueries', () => { const queryResults = useQueries({ queries: [ { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => { return { wow: true, @@ -116,7 +116,7 @@ describe('useQueries', () => { queries: [ { ...options, - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('data'), }, ], @@ -134,7 +134,7 @@ describe('useQueries', () => { const queryResults = useQueries({ queries: [ { - queryKey: queryKey(), + queryKey: createKey(), queryFn: Math.random() > 0.5 ? skipToken : () => Promise.resolve(5), }, ], @@ -150,14 +150,14 @@ describe('useQueries', () => { const Queries1 = { get: () => queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), }), } const Queries2 = { get: () => queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(true), }), } @@ -178,9 +178,9 @@ describe('useQueries', () => { describe('type parameters', () => { it('should handle type parameter - tuple of tuples', () => { - const key1 = queryKey() - const key2 = queryKey() - const key3 = queryKey() + const key1 = createKey() + const key2 = createKey() + const key3 = createKey() // @ts-expect-error (Page component is not rendered) function Page() { @@ -291,9 +291,9 @@ describe('useQueries', () => { }) it('should handle type parameter - tuple of objects', () => { - const key1 = queryKey() - const key2 = queryKey() - const key3 = queryKey() + const key1 = createKey() + const key2 = createKey() + const key3 = createKey() // @ts-expect-error (Page component is not rendered) function Page() { @@ -452,7 +452,7 @@ describe('useQueries', () => { const result4 = useQueries({ queries: [ queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 'string', select: (a) => { expectTypeOf(a).toEqualTypeOf() @@ -460,7 +460,7 @@ describe('useQueries', () => { }, }), queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 'string', select: (a) => { expectTypeOf(a).toEqualTypeOf() @@ -477,11 +477,11 @@ describe('useQueries', () => { }) it('should handle array literal without type parameter to infer result type', () => { - const key1 = queryKey() - const key2 = queryKey() - const key3 = queryKey() - const key4 = queryKey() - const key5 = queryKey() + const key1 = createKey() + const key2 = createKey() + const key3 = createKey() + const key4 = createKey() + const key5 = createKey() type BizError = { code: number } const throwOnError = (_error: BizError) => true diff --git a/packages/preact-query/src/__tests__/useQueries.test.tsx b/packages/preact-query/src/__tests__/useQueries.test.tsx index 986ad8b7f23..3fc05464511 100644 --- a/packages/preact-query/src/__tests__/useQueries.test.tsx +++ b/packages/preact-query/src/__tests__/useQueries.test.tsx @@ -1,4 +1,4 @@ -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { fireEvent, render } from '@testing-library/preact' import { useCallback, useEffect, useState } from 'preact/hooks' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -24,8 +24,8 @@ describe('useQueries', () => { }) it('should return the correct states', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const results: Array> = [] function Page() { @@ -65,7 +65,7 @@ describe('useQueries', () => { }) it('should not optimistically show fetching when unsubscribed', () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => Promise.resolve('data')) function Page() { @@ -93,7 +93,7 @@ describe('useQueries', () => { }) it('should track results', async () => { - const key1 = queryKey() + const key1 = createKey() const results: Array> = [] let count = 0 @@ -141,10 +141,10 @@ describe('useQueries', () => { it("should throw error if in one of queries' queryFn throws and throwOnError is in use", async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key1 = queryKey() - const key2 = queryKey() - const key3 = queryKey() - const key4 = queryKey() + const key1 = createKey() + const key2 = createKey() + const key3 = createKey() + const key4 = createKey() function Page() { useQueries({ @@ -204,10 +204,10 @@ describe('useQueries', () => { it("should throw error if in one of queries' queryFn throws and throwOnError function resolves to true", async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key1 = queryKey() - const key2 = queryKey() - const key3 = queryKey() - const key4 = queryKey() + const key1 = createKey() + const key2 = createKey() + const key3 = createKey() + const key4 = createKey() function Page() { useQueries({ @@ -269,7 +269,7 @@ describe('useQueries', () => { it("should throw error if in one of queries' queryFn rejects with a falsy error and throwOnError is in use", async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() function Page() { useQueries({ @@ -302,7 +302,7 @@ describe('useQueries', () => { }) it('should use provided custom queryClient', async () => { - const key = queryKey() + const key = createKey() const queryFn = async () => { return Promise.resolve('custom client') } @@ -330,8 +330,8 @@ describe('useQueries', () => { }) it('should combine queries', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() function Page() { const queries = useQueries( @@ -374,7 +374,7 @@ describe('useQueries', () => { }) it('should not return new instances when called without queries', async () => { - const key = queryKey() + const key = createKey() const ids: Array = [] let resultChanged = 0 @@ -446,8 +446,8 @@ describe('useQueries', () => { }) it('should only call combine with query results', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() function Page() { const result = useQueries({ @@ -482,8 +482,8 @@ describe('useQueries', () => { }) it('should track property access through combine function', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() let count = 0 const results: Array = [] @@ -579,7 +579,7 @@ describe('useQueries', () => { }) it('should synchronously track properties of all observer even if a property (isLoading) is only accessed on one observer (#7000)', async () => { - const key = queryKey() + const key = createKey() const ids = [1, 2] function Page() { @@ -619,7 +619,7 @@ describe('useQueries', () => { }) it('should not have stale closures with combine (#6648)', async () => { - const key = queryKey() + const key = createKey() function Page() { const [count, setCount] = useState(0) @@ -662,8 +662,8 @@ describe('useQueries', () => { }) it('should optimize combine if it is a stable reference', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const client = new QueryClient() @@ -741,8 +741,8 @@ describe('useQueries', () => { }) it('should re-run combine if the functional reference changes', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const client = new QueryClient() @@ -808,8 +808,8 @@ describe('useQueries', () => { }) it('should not re-render if combine returns a stable reference', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const client = new QueryClient() @@ -862,9 +862,9 @@ describe('useQueries', () => { }) it('should re-render once combine returns a different reference', async () => { - const key1 = queryKey() - const key2 = queryKey() - const key3 = queryKey() + const key1 = createKey() + const key2 = createKey() + const key3 = createKey() const client = new QueryClient() @@ -917,9 +917,9 @@ describe('useQueries', () => { }) it('should track properties correctly with combine', async () => { - const key1 = queryKey() - const key2 = queryKey() - const key3 = queryKey() + const key1 = createKey() + const key2 = createKey() + const key3 = createKey() const client = new QueryClient() @@ -983,8 +983,8 @@ describe('useQueries', () => { }) it('should not re-run stable combine on unrelated re-render', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const client = new QueryClient() @@ -1057,8 +1057,8 @@ describe('useQueries', () => { it('should not cause infinite re-renders when removing last query', async () => { let renderCount = 0 - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() function Page() { const [queries, setQueries] = useState([ @@ -1126,8 +1126,8 @@ describe('useQueries', () => { }) it('should not fetch for the duration of the restoring period when isRestoring is true', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const queryFn1 = vi.fn<() => Promise>(() => sleep(10).then(() => 'data1'), ) @@ -1183,8 +1183,8 @@ describe('useQueries', () => { }) it('should not fetch queries with different durations for the duration of the restoring period when isRestoring is true', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const queryFn1 = vi.fn<() => Promise>(() => sleep(10).then(() => 'data1'), ) diff --git a/packages/preact-query/src/__tests__/useQuery.test-d.tsx b/packages/preact-query/src/__tests__/useQuery.test-d.tsx index 877a0607254..ccbb82af6c2 100644 --- a/packages/preact-query/src/__tests__/useQuery.test-d.tsx +++ b/packages/preact-query/src/__tests__/useQuery.test-d.tsx @@ -1,4 +1,4 @@ -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { assertType, describe, expectTypeOf, it } from 'vitest' import { queryOptions } from '../queryOptions' @@ -6,7 +6,7 @@ import { useQuery } from '../useQuery' import type { OmitKeyof, QueryFunction, UseQueryOptions } from '..' describe('useQuery', () => { - const key = queryKey() + const key = createKey() it('should default to unknown when the query function is unspecified', () => { const noQueryFn = useQuery({ queryKey: key }) @@ -191,7 +191,7 @@ describe('useQuery', () => { describe('Config object overload', () => { it('should always define TData when initialData is provided as an object', () => { const { data } = useQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => ({ wow: true }), initialData: { wow: true }, }) @@ -201,7 +201,7 @@ describe('useQuery', () => { it('should define TData when passed through queryOptions', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => { return { wow: true, @@ -218,7 +218,7 @@ describe('useQuery', () => { it('should be possible to define a different TData than TQueryFnData using select with queryOptions spread into useQuery', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), }) @@ -232,7 +232,7 @@ describe('useQuery', () => { it('should always define TData when initialData is provided as a function which ALWAYS returns the data', () => { const { data } = useQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => { return { wow: true, @@ -248,7 +248,7 @@ describe('useQuery', () => { it('should have undefined in the TData union when initialData is NOT provided', () => { const { data } = useQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => { return { wow: true, @@ -261,7 +261,7 @@ describe('useQuery', () => { it('should have undefined in the TData union when initialData is provided as a function which can return undefined', () => { const { data } = useQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => { return { wow: true, @@ -275,7 +275,7 @@ describe('useQuery', () => { it('should narrow TData after an isSuccess check when initialData is provided as a function which can return undefined', () => { const { data, isSuccess } = useQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => { return { wow: true, @@ -291,7 +291,7 @@ describe('useQuery', () => { it('should not have undefined in data when initialData is provided', () => { const { data } = useQuery({ - queryKey: queryKey(), + queryKey: createKey(), initialData: 42, }) @@ -305,7 +305,7 @@ describe('useQuery', () => { | { type: 'second'; second: string } const query = useQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: (): Result => ({ type: 'first', first: 'a' }), }) @@ -325,7 +325,7 @@ describe('useQuery', () => { ) => { return useQuery({ ...options, - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('data'), }) } @@ -340,7 +340,7 @@ describe('useQuery', () => { it('should be able to use structuralSharing with unknown types', () => { // https://github.com/TanStack/query/issues/6525#issuecomment-1938411343 useQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 5, structuralSharing: (oldData, newData) => { expectTypeOf(oldData).toBeUnknown() diff --git a/packages/preact-query/src/__tests__/useQuery.test.tsx b/packages/preact-query/src/__tests__/useQuery.test.tsx index 24a77ca9461..764b4563d8a 100644 --- a/packages/preact-query/src/__tests__/useQuery.test.tsx +++ b/packages/preact-query/src/__tests__/useQuery.test.tsx @@ -1,6 +1,6 @@ import { + createKey, mockVisibilityState, - queryKey, sleep, } from '@tanstack/query-test-utils' import { act, fireEvent, render } from '@testing-library/preact' @@ -54,7 +54,7 @@ describe('useQuery', () => { // See https://github.com/tannerlinsley/react-query/issues/105 it('should allow to set default data value', async () => { - const key = queryKey() + const key = createKey() function Page() { const { data = 'default' } = useQuery({ @@ -77,7 +77,7 @@ describe('useQuery', () => { }) it('should return the correct states for a successful query', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -164,7 +164,7 @@ describe('useQuery', () => { }) it('should return the correct states for an unsuccessful query', async () => { - const key = queryKey() + const key = createKey() const states: Array = [] let index = 0 @@ -280,7 +280,7 @@ describe('useQuery', () => { }) it('should set isFetchedAfterMount to true after a query has been fetched', async () => { - const key = queryKey() + const key = createKey() await queryClient .query({ @@ -315,7 +315,7 @@ describe('useQuery', () => { }) it('should not cancel an ongoing fetch when refetch is called with cancelRefetch=false if we have data already', async () => { - const key = queryKey() + const key = createKey() let fetchCount = 0 function Page() { @@ -350,7 +350,7 @@ describe('useQuery', () => { }) it('should cancel an ongoing fetch when refetch is called (cancelRefetch=true) if we have data already', async () => { - const key = queryKey() + const key = createKey() let fetchCount = 0 function Page() { @@ -385,7 +385,7 @@ describe('useQuery', () => { }) it('should not cancel an ongoing fetch when refetch is called (cancelRefetch=true) if we do not have data yet', async () => { - const key = queryKey() + const key = createKey() let fetchCount = 0 function Page() { @@ -419,7 +419,7 @@ describe('useQuery', () => { }) it('should be able to watch a query without providing a query function', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] queryClient.setQueryDefaults(key, { queryFn: () => 'data' }) @@ -439,7 +439,7 @@ describe('useQuery', () => { }) it('should pick up a query when re-mounting with gcTime 0', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -510,7 +510,7 @@ describe('useQuery', () => { }) it('should not get into an infinite loop when removing a query with gcTime 0 and rerendering', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -579,7 +579,7 @@ describe('useQuery', () => { }) it('should fetch when refetchOnMount is false and nothing has been fetched yet', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -601,7 +601,7 @@ describe('useQuery', () => { }) it('should not fetch when refetchOnMount is false and data has been fetched already', () => { - const key = queryKey() + const key = createKey() const states: Array> = [] queryClient.setQueryData(key, 'prefetched') @@ -623,7 +623,7 @@ describe('useQuery', () => { }) it('should be able to select a part of the data with select', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -648,7 +648,7 @@ describe('useQuery', () => { }) it('should be able to select a part of the data with select in object syntax', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -673,7 +673,7 @@ describe('useQuery', () => { }) it('should throw an error when a selector throws', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] const error = new Error('Select Error') @@ -702,7 +702,7 @@ describe('useQuery', () => { }) it('should not re-run a stable select when it re-renders if selector throws an error', async () => { - const key = queryKey() + const key = createKey() const error = new Error('Select Error') let runs = 0 @@ -742,7 +742,7 @@ describe('useQuery', () => { }) it('should track properties and only re-render when a tracked property changes', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] let count = 0 @@ -782,7 +782,7 @@ describe('useQuery', () => { }) it('should always re-render if we are tracking props but not using any', async () => { - const key = queryKey() + const key = createKey() let renderCount = 0 const states: Array> = [] @@ -812,7 +812,7 @@ describe('useQuery', () => { }) it('should be able to remove a query', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] let count = 0 @@ -860,7 +860,7 @@ describe('useQuery', () => { }) it('should create a new query when refetching a removed query', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] let count = 0 @@ -908,7 +908,7 @@ describe('useQuery', () => { }) it('should share equal data structures between query results', async () => { - const key = queryKey() + const key = createKey() const result1 = [ { id: '1', done: false }, @@ -976,7 +976,7 @@ describe('useQuery', () => { }) it('should use query function from hook when the existing query does not have a query function', async () => { - const key = queryKey() + const key = createKey() queryClient.setQueryData(key, 'set') @@ -1011,7 +1011,7 @@ describe('useQuery', () => { }) it('should update query stale state and refetch when invalidated with invalidateQueries', async () => { - const key = queryKey() + const key = createKey() let count = 0 function Page() { @@ -1057,7 +1057,7 @@ describe('useQuery', () => { }) it('should not update disabled query when refetching with refetchQueries', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] let count = 0 @@ -1096,7 +1096,7 @@ describe('useQuery', () => { }) it('should not refetch disabled query when invalidated with invalidateQueries', () => { - const key = queryKey() + const key = createKey() const states: Array> = [] let count = 0 @@ -1134,7 +1134,7 @@ describe('useQuery', () => { }) it('should not fetch when switching to a disabled query', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -1190,7 +1190,7 @@ describe('useQuery', () => { }) it('should keep the previous data when placeholderData is set', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -1252,7 +1252,7 @@ describe('useQuery', () => { }) it('should keep the previous data when placeholderData is set and select fn transform is used', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -1318,7 +1318,7 @@ describe('useQuery', () => { it('should keep the previous queryKey (from prevQuery) between multiple pending queries when placeholderData is set and select fn transform is used', async () => { const keys: Array | null> = [] - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -1367,7 +1367,7 @@ describe('useQuery', () => { }) it('should show placeholderData between multiple pending queries when select fn transform is used', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -1447,7 +1447,7 @@ describe('useQuery', () => { }) it('should transition to error state when placeholderData is set', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page({ count }: { count: number }) { @@ -1542,7 +1542,7 @@ describe('useQuery', () => { }) it('should not show initial data from next query if placeholderData is set', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -1610,7 +1610,7 @@ describe('useQuery', () => { }) it('should keep the previous data on disabled query when placeholderData is set', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -1698,7 +1698,7 @@ describe('useQuery', () => { }) it('should keep the previous data on disabled query when placeholderData is set and switching query key multiple times', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] queryClient.setQueryData([key, 10], 10) @@ -1778,7 +1778,7 @@ describe('useQuery', () => { }) it('should use the correct query function when components use different configurations', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function FirstComponent() { @@ -1838,7 +1838,7 @@ describe('useQuery', () => { }) it('should be able to set different stale times for a query', async () => { - const key = queryKey() + const key = createKey() const states1: Array> = [] const states2: Array> = [] @@ -1931,7 +1931,7 @@ describe('useQuery', () => { }) it('should re-render when a query becomes stale', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -1954,7 +1954,7 @@ describe('useQuery', () => { }) it('should re-render disabled observers when other observers trigger a query (#8741)', async () => { - const key = queryKey() + const key = createKey() const useUserInfoQuery = ({ id, @@ -2013,7 +2013,7 @@ describe('useQuery', () => { describe('notifyOnChangeProps', () => { it('should not re-render when it should only re-render only data change and the selected data did not change', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -2052,7 +2052,7 @@ describe('useQuery', () => { }) it('should not re-render when it should only re-render on data changes and the data did not change', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -2105,7 +2105,7 @@ describe('useQuery', () => { // See https://github.com/TanStack/query/discussions/5588 describe('function', () => { it('should not re-render when it should only re-render on data changes and the data did not change', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -2153,7 +2153,7 @@ describe('useQuery', () => { }) it('should not re-render when change props are not actively being tracked', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -2255,8 +2255,8 @@ describe('useQuery', () => { // See https://github.com/tannerlinsley/react-query/issues/137 it('should not override initial data in dependent queries', () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() function Page() { const first = useQuery({ @@ -2292,7 +2292,7 @@ describe('useQuery', () => { }) it('should update query options', () => { - const key = queryKey() + const key = createKey() const queryFn = () => sleep(10).then(() => 'data1') @@ -2308,7 +2308,7 @@ describe('useQuery', () => { }) it('should batch re-renders', async () => { - const key = queryKey() + const key = createKey() let renders = 0 @@ -2336,7 +2336,7 @@ describe('useQuery', () => { }) it('should render latest data even if preact has discarded certain renders', async () => { - const key = queryKey() + const key = createKey() function Page() { const [_newState, setNewState] = useState('state') @@ -2359,8 +2359,8 @@ describe('useQuery', () => { // See https://github.com/tannerlinsley/react-query/issues/170 it('should start with status pending, fetchStatus idle if enabled is false', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() function Page() { const first = useQuery({ @@ -2404,7 +2404,7 @@ describe('useQuery', () => { // See https://github.com/tannerlinsley/react-query/issues/144 it('should be in "pending" state by default', () => { - const key = queryKey() + const key = createKey() function Page() { const { status } = useQuery({ @@ -2421,7 +2421,7 @@ describe('useQuery', () => { }) it('should not refetch query on focus when `enabled` is set to `false`', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi .fn<(...args: Array) => string>() .mockReturnValue('data') @@ -2453,7 +2453,7 @@ describe('useQuery', () => { }) it('should not refetch stale query on focus when `refetchOnWindowFocus` is set to `false`', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] let count = 0 @@ -2483,7 +2483,7 @@ describe('useQuery', () => { }) it('should not refetch stale query on focus when `refetchOnWindowFocus` is set to a function that returns `false`', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] let count = 0 @@ -2513,7 +2513,7 @@ describe('useQuery', () => { }) it('should not refetch fresh query on focus when `refetchOnWindowFocus` is set to `true`', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] let count = 0 @@ -2543,7 +2543,7 @@ describe('useQuery', () => { }) it('should refetch fresh query on focus when `refetchOnWindowFocus` is set to `always`', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] let count = 0 @@ -2579,7 +2579,7 @@ describe('useQuery', () => { }) it('should calculate focus behavior for `refetchOnWindowFocus` depending on function', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] let count = 0 @@ -2629,7 +2629,7 @@ describe('useQuery', () => { }) it('should refetch fresh query when refetchOnMount is set to always', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] await queryClient @@ -2667,7 +2667,7 @@ describe('useQuery', () => { }) it('should refetch stale query when refetchOnMount is set to true', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] await queryClient @@ -2708,7 +2708,7 @@ describe('useQuery', () => { it('should set status to error if queryFn throws', async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() function Page() { const { status, error } = useQuery({ @@ -2736,7 +2736,7 @@ describe('useQuery', () => { it('should throw error if queryFn throws and throwOnError is in use', async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() function Page() { const { status, error } = useQuery({ @@ -2767,7 +2767,7 @@ describe('useQuery', () => { it('should throw error if queryFn rejects with a falsy error and throwOnError is in use', async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() function Page() { const { status } = useQuery({ @@ -2796,7 +2796,7 @@ describe('useQuery', () => { }) it('should update with data if we observe no properties and throwOnError', async () => { - const key = queryKey() + const key = createKey() let result: UseQueryResult | undefined @@ -2823,7 +2823,7 @@ describe('useQuery', () => { }) it('should set status to error instead of throwing when error should not be thrown', async () => { - const key = queryKey() + const key = createKey() function Page() { const { status, error } = useQuery({ @@ -2857,7 +2857,7 @@ describe('useQuery', () => { it('should throw error instead of setting status when error should be thrown', async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() function Page() { const { status, error } = useQuery({ @@ -2896,7 +2896,7 @@ describe('useQuery', () => { }) it('should continue retries when observers unmount and remount while waiting for a retry (#3031)', async () => { - const key = queryKey() + const key = createKey() let count = 0 function Page() { @@ -2952,7 +2952,7 @@ describe('useQuery', () => { }) it('should restart when observers unmount and remount while waiting for a retry when query was cancelled in between (#3031)', async () => { - const key = queryKey() + const key = createKey() let count = 0 function Page() { @@ -3012,7 +3012,7 @@ describe('useQuery', () => { }) it('should always fetch if refetchOnMount is set to always', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] await queryClient @@ -3064,7 +3064,7 @@ describe('useQuery', () => { }) it('should fetch if initial data is set', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -3095,7 +3095,7 @@ describe('useQuery', () => { }) it('should not fetch if initial data is set with a stale time', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -3126,7 +3126,7 @@ describe('useQuery', () => { }) it('should fetch if initial data updated at is older than stale time', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] const oneSecondAgo = Date.now() - 1000 @@ -3165,7 +3165,7 @@ describe('useQuery', () => { }) it('should fetch if "initial data updated at" is exactly 0', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -3197,7 +3197,7 @@ describe('useQuery', () => { }) it('should keep initial data when the query key changes', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -3230,7 +3230,7 @@ describe('useQuery', () => { }) it('should keep initialData visible alongside the error when a refetch fails', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] function Page() { @@ -3254,7 +3254,7 @@ describe('useQuery', () => { }) it('should retry specified number of times', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<(...args: Array) => unknown>() queryFn.mockRejectedValue(new Error('Error test Barrett')) @@ -3290,7 +3290,7 @@ describe('useQuery', () => { }) it('should not retry if retry function `false`', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<(...args: Array) => unknown>() @@ -3331,7 +3331,7 @@ describe('useQuery', () => { }) it('should extract retryDelay from error', async () => { - const key = queryKey() + const key = createKey() type DelayError = { delay: number } @@ -3369,7 +3369,7 @@ describe('useQuery', () => { // See https://github.com/tannerlinsley/react-query/issues/160 it('should continue retry after focus regain', async () => { - const key = queryKey() + const key = createKey() // make page unfocused const visibilityMock = mockVisibilityState('hidden') @@ -3439,7 +3439,7 @@ describe('useQuery', () => { }) it('should fetch on mount when a query was already created with setQueryData', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] queryClient.setQueryData(key, 'prefetched') @@ -3469,7 +3469,7 @@ describe('useQuery', () => { }) it('should refetch after focus regain', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] // make page unfocused @@ -3531,7 +3531,7 @@ describe('useQuery', () => { // See https://github.com/tannerlinsley/react-query/issues/195 it('should refetch if stale after a prefetch', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] const queryFn = vi.fn<(...args: Array) => string>() @@ -3566,7 +3566,7 @@ describe('useQuery', () => { }) it('should not refetch if not stale after a prefetch', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<(...args: Array) => string>() queryFn.mockReturnValue('data') @@ -3599,7 +3599,7 @@ describe('useQuery', () => { // See https://github.com/tannerlinsley/react-query/issues/190 it('should reset failureCount on successful fetch', async () => { - const key = queryKey() + const key = createKey() let counter = 0 @@ -3636,7 +3636,7 @@ describe('useQuery', () => { // See https://github.com/tannerlinsley/react-query/issues/199 it('should use prefetched data for dependent query', async () => { - const key = queryKey() + const key = createKey() let count = 0 function Page() { @@ -3690,7 +3690,7 @@ describe('useQuery', () => { }) it('should support dependent queries via the enable config option', async () => { - const key = queryKey() + const key = createKey() function Page() { const [shouldFetch, setShouldFetch] = useState(false) @@ -3726,7 +3726,7 @@ describe('useQuery', () => { }) it('should mark query as fetching, when using initialData', async () => { - const key = queryKey() + const key = createKey() const results: Array> = [] function Page() { @@ -3751,7 +3751,7 @@ describe('useQuery', () => { }) it('should initialize state properly, when initialData is falsy', async () => { - const key = queryKey() + const key = createKey() const results: Array> = [] function Page() { @@ -3773,7 +3773,7 @@ describe('useQuery', () => { }) it('should show the correct data when switching keys with initialData, placeholderData & staleTime', async () => { - const key = queryKey() + const key = createKey() const ALL_TODOS = [ { name: 'todo A', priority: 'high' }, @@ -3834,7 +3834,7 @@ describe('useQuery', () => { // // See https://github.com/tannerlinsley/react-query/issues/214 it('should persist data when enabled is changed to false', async () => { - const key = queryKey() + const key = createKey() const results: Array> = [] function Page() { @@ -3883,7 +3883,7 @@ describe('useQuery', () => { }) it('should support enabled:false in query object syntax', () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<(...args: Array) => string>() queryFn.mockReturnValue('data') @@ -3905,7 +3905,7 @@ describe('useQuery', () => { // See https://github.com/tannerlinsley/react-query/issues/360 it('should init to status:pending, fetchStatus:idle when enabled is false', async () => { - const key = queryKey() + const key = createKey() function Page() { const query = useQuery({ @@ -3930,7 +3930,7 @@ describe('useQuery', () => { }) it('should not schedule garbage collection, if gcTimeout is set to `Infinity`', async () => { - const key = queryKey() + const key = createKey() function Page() { const query = useQuery({ @@ -3955,7 +3955,7 @@ describe('useQuery', () => { }) it('should schedule garbage collection, if gcTimeout is not set to infinity', async () => { - const key = queryKey() + const key = createKey() function Page() { const query = useQuery({ @@ -3984,7 +3984,7 @@ describe('useQuery', () => { }) it('should not cause memo churn when data does not change', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi .fn<(...args: Array) => string>() .mockReturnValue('data') @@ -4035,7 +4035,7 @@ describe('useQuery', () => { }) it('should update data upon interval changes', async () => { - const key = queryKey() + const key = createKey() let count = 0 function Page() { @@ -4067,7 +4067,7 @@ describe('useQuery', () => { }) it('should refetch in an interval depending on function result', async () => { - const key = queryKey() + const key = createKey() let count = 0 const states: Array> = [] @@ -4132,7 +4132,7 @@ describe('useQuery', () => { }) it('should not interval fetch with a refetchInterval of 0', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => number>(() => 1) function Page() { @@ -4184,7 +4184,7 @@ describe('useQuery', () => { }) it('should refetch if any query instance becomes enabled', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi .fn<(...args: Array) => string>() @@ -4218,7 +4218,7 @@ describe('useQuery', () => { }) it('should use placeholder data while the query loads', async () => { - const key1 = queryKey() + const key1 = createKey() const states: Array> = [] @@ -4259,7 +4259,7 @@ describe('useQuery', () => { }) it('should use placeholder data even for disabled queries', async () => { - const key1 = queryKey() + const key1 = createKey() const states: Array<{ state: UseQueryResult; count: number }> = [] @@ -4321,7 +4321,7 @@ describe('useQuery', () => { }) it('should run placeholder data through select', async () => { - const key1 = queryKey() + const key1 = createKey() const states: Array> = [] @@ -4363,7 +4363,7 @@ describe('useQuery', () => { }) it('should run placeholder data function result through select', async () => { - const key1 = queryKey() + const key1 = createKey() const states: Array> = [] let placeholderFunctionRunCount = 0 @@ -4418,7 +4418,7 @@ describe('useQuery', () => { }) it('should only run select when dependencies change if memoized', async () => { - const key1 = queryKey() + const key1 = createKey() let selectRun = 0 @@ -4461,7 +4461,7 @@ describe('useQuery', () => { }) it('should always return the correct state from select', async () => { - const key1 = queryKey() + const key1 = createKey() function Page() { const [count, inc] = useReducer((prev) => prev + 1, 2) @@ -4508,7 +4508,7 @@ describe('useQuery', () => { }) it('should structurally share data in select', async () => { - const key1 = queryKey() + const key1 = createKey() const states: Array> = [] function Page() { @@ -4552,7 +4552,7 @@ describe('useQuery', () => { }) it('should cancel the query function when there are no more subscriptions', async () => { - const key = queryKey() + const key = createKey() let cancelFn: Mock = vi.fn<(event: Event) => void>() const queryFn = ({ signal }: { signal?: AbortSignal }) => { @@ -4590,7 +4590,7 @@ describe('useQuery', () => { }) it('should cancel the query if the signal was consumed and there are no more subscriptions', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] const queryFn: QueryFunction = async ( @@ -4654,7 +4654,7 @@ describe('useQuery', () => { }) it('should refetch when quickly switching to a failed query', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] const queryFn = () => sleep(50).then(() => 'OK') @@ -4702,7 +4702,7 @@ describe('useQuery', () => { }) it('should update query state and refetch when reset with resetQueries', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] let count = 0 @@ -4773,7 +4773,7 @@ describe('useQuery', () => { }) it('should update query state and not refetch when resetting a disabled query with resetQueries', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] let count = 0 @@ -4851,7 +4851,7 @@ describe('useQuery', () => { }) it('should only call the query hash function once each render', async () => { - const key = queryKey() + const key = createKey() let hashes = 0 let renders = 0 @@ -4877,7 +4877,7 @@ describe('useQuery', () => { }) it('should hash query keys that contain bigints given a supported query hash function', async () => { - const key = [queryKey(), 1n] + const key = [createKey(), 1n] function queryKeyHashFn(x: any) { return JSON.stringify(x, (_, value) => { @@ -4900,7 +4900,7 @@ describe('useQuery', () => { }) it('should refetch when changed enabled to true in error state', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<(...args: Array) => unknown>(() => sleep(10).then(() => Promise.reject(new Error('Suspense Error Bingo'))), ) @@ -5075,7 +5075,7 @@ describe('useQuery', () => { }) it('should have no error in pending state when refetching after error occurred', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] const error = new Error('oops') @@ -5151,7 +5151,7 @@ describe('useQuery', () => { it('should not start fetching online queries if you are offline', async () => { const onlineMock = mockOnlineManagerIsOnline(false) - const key = queryKey() + const key = createKey() const states: Array = [] function Page() { @@ -5189,7 +5189,7 @@ describe('useQuery', () => { }) it('should not refetch online queries if you are offline', async () => { - const key = queryKey() + const key = createKey() let count = 0 function Page() { @@ -5249,7 +5249,7 @@ describe('useQuery', () => { }) it('should not refetch online queries if you are offline and refocus', async () => { - const key = queryKey() + const key = createKey() let count = 0 function Page() { @@ -5295,7 +5295,7 @@ describe('useQuery', () => { }) it('should not refetch online queries while already paused', async () => { - const key = queryKey() + const key = createKey() let count = 0 function Page() { @@ -5339,7 +5339,7 @@ describe('useQuery', () => { }) it('should not refetch online queries while already paused if data is in the cache', async () => { - const key = queryKey() + const key = createKey() let count = 0 function Page() { @@ -5385,7 +5385,7 @@ describe('useQuery', () => { }) it('should not get online queries stuck in fetching state when pausing multiple times', async () => { - const key = queryKey() + const key = createKey() let count = 0 function Page() { @@ -5442,7 +5442,7 @@ describe('useQuery', () => { }) it('should pause retries of online queries if you are offline', async () => { - const key = queryKey() + const key = createKey() let count = 0 function Page() { @@ -5493,7 +5493,7 @@ describe('useQuery', () => { }) it('should not fetch online queries if paused initial load and we go online after unmount', async () => { - const key = queryKey() + const key = createKey() let count = 0 function Component() { @@ -5548,7 +5548,7 @@ describe('useQuery', () => { }) it('should re-fetch online queries if paused and we go online even if already unmounted (because not cancelled)', async () => { - const key = queryKey() + const key = createKey() let count = 0 queryClient.setQueryData(key, 'initial') @@ -5605,7 +5605,7 @@ describe('useQuery', () => { }) it('should not fetch online queries if paused and we go online when cancelled and no refetchOnReconnect', async () => { - const key = queryKey() + const key = createKey() let count = 0 function Page() { @@ -5656,7 +5656,7 @@ describe('useQuery', () => { }) it('should fetch online queries if paused and we go online even if already unmounted when refetch was not cancelled', async () => { - const key = queryKey() + const key = createKey() let count = 0 function Component() { @@ -5724,7 +5724,7 @@ describe('useQuery', () => { it('should start fetching always queries even if you are offline', async () => { mockOnlineManagerIsOnline(false) - const key = queryKey() + const key = createKey() let count = 0 function Page() { @@ -5758,7 +5758,7 @@ describe('useQuery', () => { it('should not pause retries of always queries', async () => { mockOnlineManagerIsOnline(false) - const key = queryKey() + const key = createKey() let count = 0 function Page() { @@ -5800,7 +5800,7 @@ describe('useQuery', () => { it('should start fetching offlineFirst queries if you are offline, but pause retries', async () => { const onlineMock = mockOnlineManagerIsOnline(false) - const key = queryKey() + const key = createKey() let count = 0 function Page() { @@ -5850,7 +5850,7 @@ describe('useQuery', () => { describe('subscribed', () => { it('should be able to toggle subscribed', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => Promise.resolve('data'), ) @@ -5896,7 +5896,7 @@ describe('useQuery', () => { }) it('should not optimistically show fetching when subscribed is false', () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => Promise.resolve('data'), ) @@ -5927,7 +5927,7 @@ describe('useQuery', () => { }) it('should not be attached to the query when subscribed is false', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => Promise.resolve('data'), ) @@ -5957,7 +5957,7 @@ describe('useQuery', () => { }) it('should not re-render when data is added to the cache when subscribed is false', async () => { - const key = queryKey() + const key = createKey() let renders = 0 function Page() { const { data } = useQuery({ @@ -5992,7 +5992,7 @@ describe('useQuery', () => { }) it('should have status=error on mount when a query has failed', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] const error = new Error('oops') @@ -6026,7 +6026,7 @@ describe('useQuery', () => { }) it('should respect updatedAt in setQueryData', async () => { - const key = queryKey() + const key = createKey() function Page() { const state = useQuery({ queryKey: key, queryFn: () => 'data' }) @@ -6059,7 +6059,7 @@ describe('useQuery', () => { }) it('should increase errorUpdateCount on each fetch failure', async () => { - const key = queryKey() + const key = createKey() const error = new Error('oops') function Page() { @@ -6094,7 +6094,7 @@ describe('useQuery', () => { }) it('should use provided custom queryClient', async () => { - const key = queryKey() + const key = createKey() const queryFn = async () => { return Promise.resolve('custom client') } @@ -6118,7 +6118,7 @@ describe('useQuery', () => { }) it('should be notified of updates between create and subscribe', async () => { - const key = queryKey() + const key = createKey() function Page() { const { data, status } = useQuery({ @@ -6151,7 +6151,7 @@ describe('useQuery', () => { }) it('should reuse same data object reference when queryKey changes back to some cached data', async () => { - const key = queryKey() + const key = createKey() const spy = vi.fn<(data: unknown) => void>() async function fetchNumber(id: number) { @@ -6217,7 +6217,7 @@ describe('useQuery', () => { }) it('should reuse same data object reference when queryKey changes and placeholderData is present', async () => { - const key = queryKey() + const key = createKey() const spy = vi.fn<(data: unknown) => void>() async function fetchNumber(id: number) { @@ -6286,7 +6286,7 @@ describe('useQuery', () => { }) it('should not cause an infinite render loop when using unstable callback ref', async () => { - const key = queryKey() + const key = createKey() function Test() { const [_ref, setRef] = useState() @@ -6306,7 +6306,7 @@ describe('useQuery', () => { }) it('should keep the previous data when placeholderData is set and cache is used', async () => { - const key = queryKey() + const key = createKey() const states: Array> = [] const steps = [0, 1, 0, 2] @@ -6403,7 +6403,7 @@ describe('useQuery', () => { // Mock console error to avoid noise when test is run vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() const queryFn = () => 'data' function Page() { @@ -6417,7 +6417,7 @@ describe('useQuery', () => { }) it('should respect skipToken and refetch when skipToken is taken away', async () => { - const key = queryKey() + const key = createKey() function Page({ enabled }: { enabled: boolean }) { const { data, status } = useQuery({ @@ -6464,7 +6464,7 @@ describe('useQuery', () => { const consoleErrorMock = vi .spyOn(console, 'error') .mockReturnValue(undefined) - const key = queryKey() + const key = createKey() function App() { const query = useQuery({ @@ -6491,7 +6491,7 @@ describe('useQuery', () => { }) it('should return correct optimistic result when fetching after error', async () => { - const key = queryKey() + const key = createKey() const error = new Error('oh no') const results: Array> = [] @@ -6589,7 +6589,7 @@ describe('useQuery', () => { }) it('should pick up an initialPromise', async () => { - const key = queryKey() + const key = createKey() const serverQueryClient = new QueryClient({ defaultOptions: { dehydrate: { shouldDehydrateQuery: () => true } }, @@ -6643,7 +6643,7 @@ describe('useQuery', () => { const consoleErrorMock = vi .spyOn(console, 'error') .mockReturnValue(undefined) - const key = queryKey() + const key = createKey() const serverQueryClient = new QueryClient({ defaultOptions: { @@ -6704,7 +6704,7 @@ describe('useQuery', () => { it('should console.error when there is no queryFn', () => { const consoleErrorMock = vi.spyOn(console, 'error') - const key = queryKey() + const key = createKey() function Example() { useQuery({ queryKey: key }) return <> @@ -6718,7 +6718,7 @@ describe('useQuery', () => { }) it('should not fetch for the duration of the restoring period when isRestoring is true', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => sleep(10).then(() => 'data'), ) @@ -6758,7 +6758,7 @@ describe('useQuery', () => { }) it('should retry on mount when throwOnError returns false', async () => { - const key = queryKey() + const key = createKey() let fetchCount = 0 const queryFn = vi.fn<() => Promise>().mockImplementation(() => { fetchCount++ @@ -6806,7 +6806,7 @@ describe('useQuery', () => { }) it('should not retry on mount when throwOnError function returns true', async () => { - const key = queryKey() + const key = createKey() let fetchCount = 0 const queryFn = vi.fn<() => Promise>().mockImplementation(() => { fetchCount++ @@ -6880,7 +6880,7 @@ describe('useQuery', () => { }) it('should handle throwOnError function based on actual error state', async () => { - const key = queryKey() + const key = createKey() let fetchCount = 0 const queryFn = vi.fn<() => Promise>().mockImplementation(() => { fetchCount++ @@ -6930,7 +6930,7 @@ describe('useQuery', () => { }) it('should retry on mount when throwOnError returns false for a falsy error', async () => { - const key = queryKey() + const key = createKey() const queryFn = vi.fn<() => Promise>(() => Promise.reject()) function Component() { diff --git a/packages/preact-query/src/__tests__/useSuspenseInfiniteQuery.test-d.tsx b/packages/preact-query/src/__tests__/useSuspenseInfiniteQuery.test-d.tsx index 7bd17c9dd0c..e2f499ff930 100644 --- a/packages/preact-query/src/__tests__/useSuspenseInfiniteQuery.test-d.tsx +++ b/packages/preact-query/src/__tests__/useSuspenseInfiniteQuery.test-d.tsx @@ -1,5 +1,5 @@ import { skipToken } from '@tanstack/query-core' -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { assertType, describe, expectTypeOf, it } from 'vitest' import { useSuspenseInfiniteQuery } from '../useSuspenseInfiniteQuery' @@ -9,7 +9,7 @@ import type { InfiniteData } from '@tanstack/query-core' describe('useSuspenseInfiniteQuery', () => { it('should always have data defined', () => { const { data } = useSuspenseInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), initialPageParam: 1, getNextPageParam: () => 1, @@ -21,7 +21,7 @@ describe('useSuspenseInfiniteQuery', () => { it('should not allow skipToken in queryFn', () => { assertType( useSuspenseInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), // @ts-expect-error queryFn: skipToken, }), @@ -29,7 +29,7 @@ describe('useSuspenseInfiniteQuery', () => { assertType( useSuspenseInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), // @ts-expect-error queryFn: Math.random() > 0.5 ? skipToken : () => Promise.resolve(5), }), @@ -38,7 +38,7 @@ describe('useSuspenseInfiniteQuery', () => { it('should not have pending status', () => { const { status } = useSuspenseInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), initialPageParam: 1, getNextPageParam: () => 1, @@ -50,7 +50,7 @@ describe('useSuspenseInfiniteQuery', () => { it('should not allow placeholderData, enabled or throwOnError props', () => { assertType( useSuspenseInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), initialPageParam: 1, getNextPageParam: () => 1, @@ -62,7 +62,7 @@ describe('useSuspenseInfiniteQuery', () => { assertType( useSuspenseInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), initialPageParam: 1, getNextPageParam: () => 1, @@ -73,7 +73,7 @@ describe('useSuspenseInfiniteQuery', () => { assertType( useSuspenseInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), initialPageParam: 1, getNextPageParam: () => 1, @@ -85,7 +85,7 @@ describe('useSuspenseInfiniteQuery', () => { it('should default TData of UseSuspenseInfiniteQueryOptions to InfiniteData', () => { const options: UseSuspenseInfiniteQueryOptions = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), initialPageParam: 1, getNextPageParam: () => 1, @@ -97,7 +97,7 @@ describe('useSuspenseInfiniteQuery', () => { it('should not return isPlaceholderData', () => { const query = useSuspenseInfiniteQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), initialPageParam: 1, getNextPageParam: () => 1, diff --git a/packages/preact-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx b/packages/preact-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx index b40e8346b21..650890ba4f6 100644 --- a/packages/preact-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx +++ b/packages/preact-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx @@ -1,4 +1,4 @@ -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { Suspense } from 'preact/compat' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -27,7 +27,7 @@ describe('useSuspenseInfiniteQuery', () => { const consoleErrorMock = vi .spyOn(console, 'error') .mockImplementation(() => {}) - const key = queryKey() + const key = createKey() function Page() { useSuspenseInfiniteQuery({ @@ -63,7 +63,7 @@ describe('useSuspenseInfiniteQuery', () => { const consoleErrorMock = vi .spyOn(console, 'error') .mockReturnValue(undefined) - const key = queryKey() + const key = createKey() function Page() { useSuspenseInfiniteQuery({ @@ -97,7 +97,7 @@ describe('useSuspenseInfiniteQuery', () => { const consoleErrorMock = vi .spyOn(console, 'error') .mockReturnValue(undefined) - const key = queryKey() + const key = createKey() function Page() { useSuspenseInfiniteQuery({ diff --git a/packages/preact-query/src/__tests__/useSuspenseQueries.test-d.tsx b/packages/preact-query/src/__tests__/useSuspenseQueries.test-d.tsx index 6dc6bc95684..085e01c100f 100644 --- a/packages/preact-query/src/__tests__/useSuspenseQueries.test-d.tsx +++ b/packages/preact-query/src/__tests__/useSuspenseQueries.test-d.tsx @@ -1,4 +1,4 @@ -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { assertType, describe, expectTypeOf, it } from 'vitest' import { skipToken, useSuspenseQueries } from '..' @@ -9,7 +9,7 @@ import type { UseQueryOptions, UseSuspenseQueryResult } from '../types' describe('UseSuspenseQueries config object overload', () => { it('should always define TData', () => { const query1 = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => { return { wow: true, @@ -21,7 +21,7 @@ describe('UseSuspenseQueries config object overload', () => { } const query2 = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 'Query Data', } @@ -36,7 +36,7 @@ describe('UseSuspenseQueries config object overload', () => { it('should define TData when passed through queryOptions', () => { const options = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => { return { wow: true, @@ -52,13 +52,13 @@ describe('UseSuspenseQueries config object overload', () => { it('should be possible to define a different TData than TQueryFnData using select with queryOptions spread into useQuery', () => { const query1 = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), select: (data) => data > 1, }) const query2 = { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), select: (data: number) => data > 1, } @@ -75,7 +75,7 @@ describe('UseSuspenseQueries config object overload', () => { const queryResults = useSuspenseQueries({ queries: [ { - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => { return { wow: true, @@ -96,7 +96,7 @@ describe('UseSuspenseQueries config object overload', () => { useSuspenseQueries({ queries: [ { - queryKey: queryKey(), + queryKey: createKey(), // @ts-expect-error queryFn: skipToken, }, @@ -108,7 +108,7 @@ describe('UseSuspenseQueries config object overload', () => { useSuspenseQueries({ queries: [ { - queryKey: queryKey(), + queryKey: createKey(), // @ts-expect-error queryFn: Math.random() > 0.5 ? skipToken : () => Promise.resolve(5), }, @@ -121,7 +121,7 @@ describe('UseSuspenseQueries config object overload', () => { const queryResults = useSuspenseQueries({ queries: [ { - queryKey: queryKey(), + queryKey: createKey(), // @ts-expect-error queryFn: Math.random() > 0.5 ? skipToken : () => Promise.resolve(5), }, @@ -147,7 +147,7 @@ describe('UseSuspenseQueries config object overload', () => { queries: [ { ...options, - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve('data'), }, ], @@ -165,14 +165,14 @@ describe('UseSuspenseQueries config object overload', () => { const Queries1 = { get: () => queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(1), }), } const Queries2 = { get: () => queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(true), }), } @@ -200,7 +200,7 @@ describe('UseSuspenseQueries config object overload', () => { it('should work with queryOptions with initialData on useSuspenseQueries', () => { const query1 = queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 'Query Data', initialData: 'initial data', }) @@ -217,7 +217,7 @@ describe('UseSuspenseQueries config object overload', () => { queries: [ // @ts-expect-error queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: Math.random() > 0.5 ? skipToken : () => Promise.resolve(5), }), ], @@ -229,7 +229,7 @@ describe('UseSuspenseQueries config object overload', () => { queries: [ // @ts-expect-error queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: Math.random() > 0.5 ? skipToken : () => Promise.resolve(5), initialData: 5, }), @@ -244,7 +244,7 @@ describe('UseSuspenseQueries config object overload', () => { queries: [ { ...queryOptions({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => 'Query Data', }), select(data: string) { diff --git a/packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx b/packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx index c6e45d3cd0d..7951b696dfb 100644 --- a/packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx +++ b/packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx @@ -1,4 +1,4 @@ -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { act, fireEvent, render } from '@testing-library/preact' import { Suspense, startTransition, useTransition } from 'preact/compat' import { useEffect, useRef, useState } from 'preact/hooks' @@ -111,7 +111,7 @@ describe('useSuspenseQueries', () => { }) it('should not suspend on mount if query has been already fetched', () => { - const key = queryKey() + const key = createKey() const queryFn = () => sleep(1000).then(() => 1) queryClient.setQueryData(key, queryFn) @@ -251,7 +251,7 @@ describe('useSuspenseQueries', () => { result: Array>, ) => void >() - const key = queryKey() + const key = createKey() function Page() { const data = useSuspenseQueries({ @@ -289,7 +289,7 @@ describe('useSuspenseQueries', () => { }) it('should handle duplicate query keys without infinite loops', async () => { - const key = queryKey() + const key = createKey() const localDuration = 10 let renderCount = 0 @@ -356,8 +356,8 @@ describe('useSuspenseQueries', () => { }) it('should suspend all queries in parallel', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const results: Array = [] function Fallback() { @@ -409,8 +409,8 @@ describe('useSuspenseQueries', () => { }) it('should not unmount before all promises fetched', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() const results: Array = [] const refs: Array = [] @@ -526,7 +526,7 @@ describe('useSuspenseQueries', () => { it('should throw error when a queryFn rejects with a falsy error', async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() function Page() { const [query] = useSuspenseQueries({ @@ -564,7 +564,7 @@ describe('useSuspenseQueries', () => { const consoleErrorMock = vi .spyOn(console, 'error') .mockReturnValue(undefined) - const key = queryKey() + const key = createKey() function Page({ fail }: { fail: boolean }) { const { data } = useSuspenseQuery({ @@ -612,7 +612,7 @@ describe('useSuspenseQueries', () => { }) it('should keep previous data when wrapped in a transition', async () => { - const key = queryKey() + const key = createKey() function Page({ count, isPending }: { count: number; isPending: boolean }) { const { data } = useSuspenseQuery({ @@ -653,7 +653,7 @@ describe('useSuspenseQueries', () => { }) it('should not request old data inside transitions (issue #6486)', async () => { - const key = queryKey() + const key = createKey() let queryFnCount = 0 function App() { @@ -706,7 +706,7 @@ describe('useSuspenseQueries', () => { }) it('should still suspense if queryClient has placeholderData config', async () => { - const key = queryKey() + const key = createKey() const queryClientWithPlaceholder = new QueryClient({ defaultOptions: { queries: { @@ -762,7 +762,7 @@ describe('useSuspenseQueries', () => { it('should show error boundary even with gcTime:0 (#7853)', async () => { vi.spyOn(console, 'error').mockReturnValue(undefined) - const key = queryKey() + const key = createKey() let count = 0 function Page() { @@ -813,7 +813,7 @@ describe('useSuspenseQueries', () => { }) it('should gc when unmounted while fetching with low gcTime (#8159)', async () => { - const key = queryKey() + const key = createKey() function Page() { return ( @@ -867,7 +867,7 @@ describe('useSuspenseQueries', () => { const consoleErrorMock = vi .spyOn(console, 'error') .mockImplementation(() => {}) - const key = queryKey() + const key = createKey() function Page() { useSuspenseQueries({ @@ -905,7 +905,7 @@ describe('useSuspenseQueries', () => { const consoleErrorMock = vi .spyOn(console, 'error') .mockReturnValue(undefined) - const key = queryKey() + const key = createKey() function Page() { useSuspenseQueries({ @@ -940,7 +940,7 @@ describe('useSuspenseQueries', () => { const consoleErrorMock = vi .spyOn(console, 'error') .mockReturnValue(undefined) - const key = queryKey() + const key = createKey() function Page() { useSuspenseQueries({ @@ -967,8 +967,8 @@ describe('useSuspenseQueries', () => { }) it('should only suspend queries that are pending when the slower query already has data', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() queryClient.setQueryData(key1, 'cached') @@ -1018,8 +1018,8 @@ describe('useSuspenseQueries', () => { }) it('should only suspend queries that are pending when the faster query already has data', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() queryClient.setQueryData(key2, 'cached') @@ -1069,8 +1069,8 @@ describe('useSuspenseQueries', () => { }) it('should not suspend and not refetch when all queries have fresh cached data', () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() queryClient.setQueryData(key1, 'cached1') queryClient.setQueryData(key2, 'cached2') @@ -1121,8 +1121,8 @@ describe('useSuspenseQueries', () => { }) it('should not suspend and only refetch the stale query when one query has fresh and the other has stale cached data', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() queryClient.setQueryData(key1, 'cached1') queryClient.setQueryData(key2, 'cached2') @@ -1189,8 +1189,8 @@ describe('useSuspenseQueries', () => { }) it('should not suspend and only refetch the stale query when one query has stale and the other has fresh cached data', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() queryClient.setQueryData(key1, 'cached1') queryClient.setQueryData(key2, 'cached2') @@ -1257,8 +1257,8 @@ describe('useSuspenseQueries', () => { }) it('should not suspend but refetch when all queries have stale cached data', async () => { - const key1 = queryKey() - const key2 = queryKey() + const key1 = createKey() + const key2 = createKey() queryClient.setQueryData(key1, 'cached1') queryClient.setQueryData(key2, 'cached2') diff --git a/packages/preact-query/src/__tests__/useSuspenseQuery.test-d.tsx b/packages/preact-query/src/__tests__/useSuspenseQuery.test-d.tsx index 53adae90660..e831cd03201 100644 --- a/packages/preact-query/src/__tests__/useSuspenseQuery.test-d.tsx +++ b/packages/preact-query/src/__tests__/useSuspenseQuery.test-d.tsx @@ -1,5 +1,5 @@ import { skipToken } from '@tanstack/query-core' -import { queryKey } from '@tanstack/query-test-utils' +import { createKey } from '@tanstack/query-test-utils' import { assertType, describe, expectTypeOf, it } from 'vitest' import { useSuspenseQuery } from '../useSuspenseQuery' @@ -7,7 +7,7 @@ import { useSuspenseQuery } from '../useSuspenseQuery' describe('useSuspenseQuery', () => { it('should always have data defined', () => { const { data } = useSuspenseQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }) @@ -16,7 +16,7 @@ describe('useSuspenseQuery', () => { it('should not have pending status', () => { const { status } = useSuspenseQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }) @@ -26,14 +26,14 @@ describe('useSuspenseQuery', () => { it('should not allow skipToken in queryFn', () => { assertType( useSuspenseQuery({ - queryKey: queryKey(), + queryKey: createKey(), // @ts-expect-error queryFn: skipToken, }), ) assertType( useSuspenseQuery({ - queryKey: queryKey(), + queryKey: createKey(), // @ts-expect-error queryFn: Math.random() > 0.5 ? skipToken : () => Promise.resolve(5), }), @@ -43,7 +43,7 @@ describe('useSuspenseQuery', () => { it('should not allow placeholderData, enabled or throwOnError props', () => { assertType( useSuspenseQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), // @ts-expect-error TS2345 placeholderData: 5, @@ -52,7 +52,7 @@ describe('useSuspenseQuery', () => { ) assertType( useSuspenseQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), // @ts-expect-error TS2345 enabled: true, @@ -60,7 +60,7 @@ describe('useSuspenseQuery', () => { ) assertType( useSuspenseQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), // @ts-expect-error TS2345 throwOnError: true, @@ -71,7 +71,7 @@ describe('useSuspenseQuery', () => { it('should not return isPlaceholderData', () => { expectTypeOf( useSuspenseQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }), ).not.toHaveProperty('isPlaceholderData') @@ -79,7 +79,7 @@ describe('useSuspenseQuery', () => { it('should type-narrow the error field', () => { const query = useSuspenseQuery({ - queryKey: queryKey(), + queryKey: createKey(), queryFn: () => Promise.resolve(5), }) diff --git a/packages/preact-query/src/__tests__/useSuspenseQuery.test.tsx b/packages/preact-query/src/__tests__/useSuspenseQuery.test.tsx index a3fd63e4ce1..be3d5f127f2 100644 --- a/packages/preact-query/src/__tests__/useSuspenseQuery.test.tsx +++ b/packages/preact-query/src/__tests__/useSuspenseQuery.test.tsx @@ -1,4 +1,4 @@ -import { queryKey, sleep } from '@tanstack/query-test-utils' +import { createKey, sleep } from '@tanstack/query-test-utils' import { act, fireEvent } from '@testing-library/preact' import { Suspense } from 'preact/compat' import { useReducer, useState } from 'preact/hooks' @@ -51,11 +51,14 @@ describe('useSuspenseQuery', () => { function TestApp() { // State lives here, ABOVE the Suspense boundary, so it does not get reset - const [stateKey, setStateKey] = useState(queryKey()) + const [stateKey, setStateKey] = useState(createKey()) return ( <> -