diff --git a/packages/solid-query/src/__tests__/createQueries.test-d.tsx b/packages/solid-query/src/__tests__/createQueries.test-d.tsx index 6c378912f6..2ac4e56e0c 100644 --- a/packages/solid-query/src/__tests__/createQueries.test-d.tsx +++ b/packages/solid-query/src/__tests__/createQueries.test-d.tsx @@ -1,4 +1,5 @@ import { describe, expectTypeOf, it } from 'vitest' +import { queryKey } from '@tanstack/query-test-utils' import { queryOptions, useQueries } from '..' import type { UseQueryResult } from '..' @@ -7,14 +8,14 @@ describe('useQueries', () => { const Queries1 = { get: () => queryOptions({ - queryKey: ['key1'], + queryKey: queryKey(), queryFn: () => Promise.resolve(1), }), } const Queries2 = { get: () => queryOptions({ - queryKey: ['key2'], + queryKey: queryKey(), queryFn: () => Promise.resolve(true), }), } diff --git a/packages/solid-query/src/__tests__/infiniteQueryOptions.test-d.tsx b/packages/solid-query/src/__tests__/infiniteQueryOptions.test-d.tsx index 6d9443cf25..5d212f7edf 100644 --- a/packages/solid-query/src/__tests__/infiniteQueryOptions.test-d.tsx +++ b/packages/solid-query/src/__tests__/infiniteQueryOptions.test-d.tsx @@ -1,5 +1,6 @@ import { describe, expectTypeOf, it } from 'vitest' import { dataTagSymbol } from '@tanstack/query-core' +import { queryKey } from '@tanstack/query-test-utils' import { useInfiniteQuery } from '../useInfiniteQuery' import { infiniteQueryOptions } from '../infiniteQueryOptions' import type { InfiniteData } from '@tanstack/query-core' @@ -12,7 +13,7 @@ describe('infiniteQueryOptions', () => { it('should infer defined types', () => { const options = infiniteQueryOptions({ getNextPageParam: () => 10, - queryKey: ['key'], + queryKey: queryKey(), queryFn: () => ({ wow: true }), initialData: { pageParams: [undefined], @@ -45,7 +46,7 @@ describe('infiniteQueryOptions', () => { it('should work without defined types', () => { const options = infiniteQueryOptions({ getNextPageParam: () => undefined, - queryKey: ['key'], + queryKey: queryKey(), queryFn: () => ({ wow: true }), initialPageParam: 0, }) diff --git a/packages/solid-query/src/__tests__/mutationOptions.test-d.tsx b/packages/solid-query/src/__tests__/mutationOptions.test-d.tsx index f90d720f0f..1649db1e01 100644 --- a/packages/solid-query/src/__tests__/mutationOptions.test-d.tsx +++ b/packages/solid-query/src/__tests__/mutationOptions.test-d.tsx @@ -1,5 +1,6 @@ import { assertType, describe, expectTypeOf, it } from 'vitest' import { QueryClient } from '@tanstack/query-core' +import { queryKey } from '@tanstack/query-test-utils' import { useIsMutating, useMutation, useMutationState } from '..' import { mutationOptions } from '../mutationOptions' import type { @@ -15,7 +16,7 @@ describe('mutationOptions', () => { // @ts-expect-error this is a good error, because onMutates does not exist! mutationOptions({ mutationFn: () => Promise.resolve(5), - mutationKey: ['key'], + mutationKey: queryKey(), onMutates: 1000, onSuccess: (data) => { expectTypeOf(data).toEqualTypeOf() @@ -26,7 +27,7 @@ describe('mutationOptions', () => { it('should infer types for callbacks', () => { mutationOptions({ mutationFn: () => Promise.resolve(5), - mutationKey: ['key'], + mutationKey: queryKey(), onSuccess: (data) => { expectTypeOf(data).toEqualTypeOf() }, @@ -38,7 +39,7 @@ describe('mutationOptions', () => { mutationFn: () => { throw new Error('fail') }, - mutationKey: ['key'], + mutationKey: queryKey(), onError: (error) => { expectTypeOf(error).toEqualTypeOf() }, @@ -51,14 +52,14 @@ describe('mutationOptions', () => { expectTypeOf(vars).toEqualTypeOf<{ id: string }>() return Promise.resolve(5) }, - mutationKey: ['with-vars'], + mutationKey: queryKey(), }) }) it('should infer result type correctly', () => { mutationOptions({ mutationFn: () => Promise.resolve(5), - mutationKey: ['key'], + mutationKey: queryKey(), onMutate: () => { return { name: 'onMutateResult' } }, @@ -74,7 +75,7 @@ describe('mutationOptions', () => { expectTypeOf(context).toEqualTypeOf() return Promise.resolve(5) }, - mutationKey: ['key'], + mutationKey: queryKey(), onMutate: (_variables, context) => { expectTypeOf(context).toEqualTypeOf() }, @@ -112,7 +113,7 @@ describe('mutationOptions', () => { expectTypeOf( mutationOptions({ mutationFn: (id: string) => Promise.resolve(id.length), - mutationKey: ['key'], + mutationKey: queryKey(), onSuccess: (data) => { expectTypeOf(data).toEqualTypeOf() }, @@ -138,7 +139,7 @@ describe('mutationOptions', () => { it('should infer types when used with useMutation', () => { const mutation = useMutation(() => mutationOptions({ - mutationKey: ['key'], + mutationKey: queryKey(), mutationFn: () => Promise.resolve('data'), onSuccess: (data) => { expectTypeOf(data).toEqualTypeOf() @@ -163,7 +164,7 @@ describe('mutationOptions', () => { it('should infer types when used with useIsMutating', () => { const isMutating = useIsMutating(() => mutationOptions({ - mutationKey: ['key'], + mutationKey: queryKey(), mutationFn: () => Promise.resolve(5), }), ) @@ -183,7 +184,7 @@ describe('mutationOptions', () => { const isMutating = queryClient.isMutating( mutationOptions({ - mutationKey: ['key'], + mutationKey: queryKey(), mutationFn: () => Promise.resolve(5), }), ) @@ -200,7 +201,7 @@ describe('mutationOptions', () => { it('should infer types when used with useMutationState', () => { const mutationState = useMutationState(() => ({ filters: mutationOptions({ - mutationKey: ['key'], + mutationKey: queryKey(), mutationFn: () => Promise.resolve(5), }), })) diff --git a/packages/solid-query/src/__tests__/mutationOptions.test.tsx b/packages/solid-query/src/__tests__/mutationOptions.test.tsx index 746b515f35..ea0e568f6a 100644 --- a/packages/solid-query/src/__tests__/mutationOptions.test.tsx +++ b/packages/solid-query/src/__tests__/mutationOptions.test.tsx @@ -1,7 +1,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { fireEvent, render } from '@solidjs/testing-library' import { createEffect, createRenderEffect } from 'solid-js' -import { sleep } from '@tanstack/query-test-utils' +import { queryKey, sleep } from '@tanstack/query-test-utils' import { QueryClient, QueryClientProvider, @@ -41,8 +41,9 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with useIsMutating (with mutationKey in mutationOptions)', async () => { const isMutatingArray: Array = [] const queryClient = new QueryClient() + const key = queryKey() const mutationOpts = mutationOptions({ - mutationKey: ['key'], + mutationKey: key, mutationFn: () => sleep(50).then(() => 'data'), }) @@ -116,8 +117,9 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with useIsMutating', async () => { const isMutatingArray: Array = [] const queryClient = new QueryClient() + const key = queryKey() const mutationOpts1 = mutationOptions({ - mutationKey: ['key'], + mutationKey: key, mutationFn: () => sleep(50).then(() => 'data1'), }) const mutationOpts2 = mutationOptions({ @@ -159,8 +161,9 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with useIsMutating (filter mutationOpts1.mutationKey)', async () => { const isMutatingArray: Array = [] const queryClient = new QueryClient() + const key = queryKey() const mutationOpts1 = mutationOptions({ - mutationKey: ['key'], + mutationKey: key, mutationFn: () => sleep(50).then(() => 'data1'), }) const mutationOpts2 = mutationOptions({ @@ -205,8 +208,9 @@ 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 mutationOpts = mutationOptions({ - mutationKey: ['mutation'], + mutationKey: key, mutationFn: () => sleep(500).then(() => 'data'), }) @@ -288,8 +292,9 @@ 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 mutationOpts1 = mutationOptions({ - mutationKey: ['mutation'], + mutationKey: key, mutationFn: () => sleep(500).then(() => 'data1'), }) const mutationOpts2 = mutationOptions({ @@ -336,8 +341,9 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with queryClient.isMutating (filter mutationOpt1.mutationKey)', async () => { const isMutatingArray: Array = [] const queryClient = new QueryClient() + const key = queryKey() const mutationOpts1 = mutationOptions({ - mutationKey: ['mutation'], + mutationKey: key, mutationFn: () => sleep(500).then(() => 'data1'), }) const mutationOpts2 = mutationOptions({ @@ -392,8 +398,9 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with useMutationState (with mutationKey in mutationOptions)', async () => { const mutationStateArray: Array> = [] const queryClient = new QueryClient() + const key = queryKey() const mutationOpts = mutationOptions({ - mutationKey: ['mutation'], + mutationKey: key, mutationFn: () => sleep(10).then(() => 'data'), }) @@ -471,8 +478,9 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with useMutationState', async () => { const mutationStateArray: Array> = [] const queryClient = new QueryClient() + const key = queryKey() const mutationOpts1 = mutationOptions({ - mutationKey: ['mutation'], + mutationKey: key, mutationFn: () => sleep(10).then(() => 'data1'), }) const mutationOpts2 = mutationOptions({ @@ -518,8 +526,9 @@ describe('mutationOptions', () => { it('should return the number of fetching mutations when used with useMutationState (filter mutationOpt1.mutationKey)', async () => { const mutationStateArray: Array> = [] const queryClient = new QueryClient() + const key = queryKey() const mutationOpts1 = mutationOptions({ - mutationKey: ['mutation'], + mutationKey: key, mutationFn: () => sleep(10).then(() => 'data1'), }) const mutationOpts2 = mutationOptions({ diff --git a/packages/solid-query/src/__tests__/queryOptions.test-d.tsx b/packages/solid-query/src/__tests__/queryOptions.test-d.tsx index 2ba3a3f6b2..299536290e 100644 --- a/packages/solid-query/src/__tests__/queryOptions.test-d.tsx +++ b/packages/solid-query/src/__tests__/queryOptions.test-d.tsx @@ -5,6 +5,7 @@ import { dataTagSymbol, skipToken, } from '@tanstack/query-core' +import { queryKey } from '@tanstack/query-test-utils' import { useQuery } from '../useQuery' import { queryOptions } from '../queryOptions' @@ -12,7 +13,7 @@ describe('queryOptions', () => { it('should not allow excess properties', () => { assertType( queryOptions({ - queryKey: ['key'], + queryKey: queryKey(), queryFn: () => Promise.resolve(5), // @ts-expect-error this is a good error, because stallTime does not exist! stallTime: 1000, @@ -21,7 +22,7 @@ describe('queryOptions', () => { }) it('should infer types for callbacks', () => { queryOptions({ - queryKey: ['key'], + queryKey: queryKey(), queryFn: () => Promise.resolve(5), staleTime: 1000, select: (data) => { @@ -31,7 +32,7 @@ describe('queryOptions', () => { }) it('should work when passed to useQuery', () => { const options = queryOptions({ - queryKey: ['key'], + queryKey: queryKey(), queryFn: () => Promise.resolve(5), }) @@ -40,7 +41,7 @@ describe('queryOptions', () => { }) it('should work when passed to fetchQuery', async () => { const options = queryOptions({ - queryKey: ['key'], + queryKey: queryKey(), queryFn: () => Promise.resolve(5), }) @@ -48,98 +49,98 @@ describe('queryOptions', () => { expectTypeOf(data).toEqualTypeOf() }) it('should tag the queryKey with the result type of the QueryFn', () => { - const { queryKey } = queryOptions({ - queryKey: ['key'], + const { queryKey: tagged } = queryOptions({ + queryKey: queryKey(), queryFn: () => Promise.resolve(5), }) - expectTypeOf(queryKey[dataTagSymbol]).toEqualTypeOf() + expectTypeOf(tagged[dataTagSymbol]).toEqualTypeOf() }) it('should tag the queryKey even if no promise is returned', () => { - const { queryKey } = queryOptions({ - queryKey: ['key'], + const { queryKey: tagged } = queryOptions({ + queryKey: queryKey(), queryFn: () => 5, }) - expectTypeOf(queryKey[dataTagSymbol]).toEqualTypeOf() + expectTypeOf(tagged[dataTagSymbol]).toEqualTypeOf() }) it('should tag the queryKey with unknown if there is no queryFn', () => { - const { queryKey } = queryOptions({ - queryKey: ['key'], + const { queryKey: tagged } = queryOptions({ + queryKey: queryKey(), }) - expectTypeOf(queryKey[dataTagSymbol]).toEqualTypeOf() + expectTypeOf(tagged[dataTagSymbol]).toEqualTypeOf() }) it('should tag the queryKey with the result type of the QueryFn if select is used', () => { - const { queryKey } = queryOptions({ - queryKey: ['key'], + const { queryKey: tagged } = queryOptions({ + queryKey: queryKey(), queryFn: () => Promise.resolve(5), select: (data) => data.toString(), }) - expectTypeOf(queryKey[dataTagSymbol]).toEqualTypeOf() + expectTypeOf(tagged[dataTagSymbol]).toEqualTypeOf() }) it('should tag the queryKey with the default error type', () => { - const { queryKey } = queryOptions({ - queryKey: ['key'], + const { queryKey: tagged } = queryOptions({ + queryKey: queryKey(), queryFn: () => Promise.resolve(1), }) - expectTypeOf(queryKey[dataTagErrorSymbol]).toEqualTypeOf() + expectTypeOf(tagged[dataTagErrorSymbol]).toEqualTypeOf() }) it('should return the proper type when passed to getQueryData', () => { - const { queryKey } = queryOptions({ - queryKey: ['key'], + const { queryKey: tagged } = queryOptions({ + queryKey: queryKey(), queryFn: () => Promise.resolve(5), }) const queryClient = new QueryClient() - const data = queryClient.getQueryData(queryKey) + const data = queryClient.getQueryData(tagged) expectTypeOf(data).toEqualTypeOf() }) it('should return the proper type when passed to getQueryState', () => { - const { queryKey } = queryOptions({ - queryKey: ['key'], + const { queryKey: tagged } = queryOptions({ + queryKey: queryKey(), queryFn: () => Promise.resolve(5), }) const queryClient = new QueryClient() - const state = queryClient.getQueryState(queryKey) + const state = queryClient.getQueryState(tagged) expectTypeOf(state?.data).toEqualTypeOf() }) it('should properly type updaterFn when passed to setQueryData', () => { - const { queryKey } = queryOptions({ - queryKey: ['key'], + const { queryKey: tagged } = queryOptions({ + queryKey: queryKey(), queryFn: () => Promise.resolve(5), }) const queryClient = new QueryClient() - const data = queryClient.setQueryData(queryKey, (prev) => { + const data = queryClient.setQueryData(tagged, (prev) => { expectTypeOf(prev).toEqualTypeOf() return prev }) expectTypeOf(data).toEqualTypeOf() }) it('should properly type value when passed to setQueryData', () => { - const { queryKey } = queryOptions({ - queryKey: ['key'], + const { queryKey: tagged } = queryOptions({ + queryKey: queryKey(), queryFn: () => Promise.resolve(5), }) const queryClient = new QueryClient() // @ts-expect-error value should be a number - queryClient.setQueryData(queryKey, '5') + queryClient.setQueryData(tagged, '5') // @ts-expect-error value should be a number - queryClient.setQueryData(queryKey, () => '5') + queryClient.setQueryData(tagged, () => '5') - const data = queryClient.setQueryData(queryKey, 5) + const data = queryClient.setQueryData(tagged, 5) expectTypeOf(data).toEqualTypeOf() }) it('should infer even if there is a conditional skipToken', () => { const options = queryOptions({ - queryKey: ['key'], + queryKey: queryKey(), queryFn: Math.random() > 0.5 ? skipToken : () => Promise.resolve(5), }) @@ -150,7 +151,7 @@ describe('queryOptions', () => { it('should infer to unknown if we disable a query with just a skipToken', () => { const options = queryOptions({ - queryKey: ['key'], + queryKey: queryKey(), queryFn: skipToken, }) diff --git a/packages/solid-query/src/__tests__/useIsMutating.test.tsx b/packages/solid-query/src/__tests__/useIsMutating.test.tsx index 076081be0b..985ce05470 100644 --- a/packages/solid-query/src/__tests__/useIsMutating.test.tsx +++ b/packages/solid-query/src/__tests__/useIsMutating.test.tsx @@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { fireEvent, render } from '@solidjs/testing-library' import { Show, createEffect, createRenderEffect, createSignal } from 'solid-js' import * as QueryCore from '@tanstack/query-core' -import { sleep } from '@tanstack/query-test-utils' +import { queryKey, sleep } from '@tanstack/query-test-utils' import { QueryClient, QueryClientProvider, @@ -23,6 +23,8 @@ describe('useIsMutating', () => { it('should return the number of fetching mutations', async () => { const isMutatingArray: Array = [] const queryClient = new QueryClient() + const mutationKey1 = queryKey() + const mutationKey2 = queryKey() function IsMutating() { const isMutating = useIsMutating() @@ -36,11 +38,11 @@ describe('useIsMutating', () => { function Mutations() { const { mutate: mutate1 } = useMutation(() => ({ - mutationKey: ['mutation1'], + mutationKey: mutationKey1, mutationFn: () => sleep(150).then(() => 'data'), })) const { mutate: mutate2 } = useMutation(() => ({ - mutationKey: ['mutation2'], + mutationKey: mutationKey2, mutationFn: () => sleep(50).then(() => 'data'), })) @@ -77,9 +79,11 @@ describe('useIsMutating', () => { it('should filter correctly by mutationKey', async () => { const isMutatingArray: Array = [] const queryClient = new QueryClient() + const mutationKey1 = queryKey() + const mutationKey2 = queryKey() function IsMutating() { - const isMutating = useIsMutating(() => ({ mutationKey: ['mutation1'] })) + const isMutating = useIsMutating(() => ({ mutationKey: mutationKey1 })) createRenderEffect(() => { isMutatingArray.push(isMutating()) @@ -90,11 +94,11 @@ describe('useIsMutating', () => { function Page() { const { mutate: mutate1 } = useMutation(() => ({ - mutationKey: ['mutation1'], + mutationKey: mutationKey1, mutationFn: () => sleep(100).then(() => 'data'), })) const { mutate: mutate2 } = useMutation(() => ({ - mutationKey: ['mutation2'], + mutationKey: mutationKey2, mutationFn: () => sleep(100).then(() => 'data'), })) @@ -121,11 +125,13 @@ describe('useIsMutating', () => { it('should filter correctly by predicate', async () => { const isMutatingArray: Array = [] const queryClient = new QueryClient() + const mutationKey1 = queryKey() + const mutationKey2 = queryKey() function IsMutating() { const isMutating = useIsMutating(() => ({ predicate: (mutation) => - mutation.options.mutationKey?.[0] === 'mutation1', + mutation.options.mutationKey?.[0] === mutationKey1[0], })) createRenderEffect(() => { @@ -137,11 +143,11 @@ describe('useIsMutating', () => { function Page() { const { mutate: mutate1 } = useMutation(() => ({ - mutationKey: ['mutation1'], + mutationKey: mutationKey1, mutationFn: () => sleep(100).then(() => 'data'), })) const { mutate: mutate2 } = useMutation(() => ({ - mutationKey: ['mutation2'], + mutationKey: mutationKey2, mutationFn: () => sleep(100).then(() => 'data'), })) @@ -167,12 +173,13 @@ describe('useIsMutating', () => { it('should use provided custom queryClient', async () => { const queryClient = new QueryClient() + const mutationKey1 = queryKey() function Page() { const isMutating = useIsMutating(undefined, () => queryClient) const { mutate } = useMutation( () => ({ - mutationKey: ['mutation1'], + mutationKey: mutationKey1, mutationFn: () => sleep(20).then(() => 'data'), }), () => queryClient, @@ -218,6 +225,7 @@ describe('useIsMutating', () => { }) const queryClient = new QueryClient() + const mutationKey1 = queryKey() function IsMutating() { useIsMutating() @@ -228,7 +236,7 @@ describe('useIsMutating', () => { const [mounted, setMounted] = createSignal(true) const { mutate: mutate1 } = useMutation(() => ({ - mutationKey: ['mutation1'], + mutationKey: mutationKey1, mutationFn: () => sleep(10).then(() => 'data'), })) diff --git a/packages/solid-query/src/__tests__/useMutationState.test.tsx b/packages/solid-query/src/__tests__/useMutationState.test.tsx index d71d77ba9f..020d24140b 100644 --- a/packages/solid-query/src/__tests__/useMutationState.test.tsx +++ b/packages/solid-query/src/__tests__/useMutationState.test.tsx @@ -1,7 +1,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { fireEvent, render } from '@solidjs/testing-library' import { createEffect } from 'solid-js' -import { sleep } from '@tanstack/query-test-utils' +import { queryKey, sleep } from '@tanstack/query-test-utils' import { QueryClient, QueryClientProvider, @@ -20,7 +20,7 @@ describe('useMutationState', () => { it('should return all mutation states when called without options', async () => { const queryClient = new QueryClient() - const mutationKey = ['mutation'] + const mutationKey = queryKey() function States() { const mutationStates = useMutationState() @@ -69,7 +69,7 @@ describe('useMutationState', () => { it('should return variables after calling mutate', async () => { const queryClient = new QueryClient() const variables: Array> = [] - const mutationKey = ['mutation'] + const mutationKey = queryKey() function Variables() { const states = useMutationState(() => ({ diff --git a/packages/solid-query/src/__tests__/useQuery.test-d.tsx b/packages/solid-query/src/__tests__/useQuery.test-d.tsx index ec11493862..64eaa5eb69 100644 --- a/packages/solid-query/src/__tests__/useQuery.test-d.tsx +++ b/packages/solid-query/src/__tests__/useQuery.test-d.tsx @@ -1,4 +1,5 @@ import { describe, expectTypeOf, it } from 'vitest' +import { queryKey } from '@tanstack/query-test-utils' import { queryOptions, useQuery } from '../index' describe('useQuery', () => { @@ -6,7 +7,7 @@ describe('useQuery', () => { describe('Config object overload', () => { it('TData should always be defined when initialData is provided as an object', () => { const { data } = useQuery(() => ({ - queryKey: ['key'], + queryKey: queryKey(), queryFn: () => ({ wow: true }), initialData: { wow: true }, })) @@ -16,7 +17,7 @@ describe('useQuery', () => { it('TData should be defined when passed through queryOptions', () => { const options = queryOptions({ - queryKey: ['key'], + queryKey: queryKey(), queryFn: () => ({ wow: true }), initialData: { wow: true }, }) @@ -27,7 +28,7 @@ describe('useQuery', () => { it('TData should always be defined when initialData is provided as a function which ALWAYS returns the data', () => { const { data } = useQuery(() => ({ - queryKey: ['key'], + queryKey: queryKey(), queryFn: () => ({ wow: true }), initialData: () => ({ wow: true }), })) @@ -37,7 +38,7 @@ describe('useQuery', () => { it('TData should have undefined in the union when initialData is NOT provided', () => { const { data } = useQuery(() => ({ - queryKey: ['key'], + queryKey: queryKey(), queryFn: () => ({ wow: true }), })) @@ -46,7 +47,7 @@ describe('useQuery', () => { it('TData should have undefined in the union when initialData is provided as a function which can return undefined', () => { const { data } = useQuery(() => ({ - queryKey: ['key'], + queryKey: queryKey(), queryFn: () => ({ wow: true }), initialData: () => undefined as { wow: boolean } | undefined, })) @@ -58,7 +59,7 @@ describe('useQuery', () => { describe('Query key overload', () => { it('TData should always be defined when initialData is provided', () => { const { data } = useQuery(() => ({ - queryKey: ['key'], + queryKey: queryKey(), queryFn: () => ({ wow: true }), initialData: { wow: true }, })) @@ -68,7 +69,7 @@ describe('useQuery', () => { it('TData should have undefined in the union when initialData is NOT provided', () => { const { data } = useQuery(() => ({ - queryKey: ['key'], + queryKey: queryKey(), queryFn: () => ({ wow: true }), })) @@ -79,7 +80,7 @@ describe('useQuery', () => { describe('Query key and func', () => { it('TData should always be defined when initialData is provided', () => { const { data } = useQuery(() => ({ - queryKey: ['key'], + queryKey: queryKey(), queryFn: () => ({ wow: true }), initialData: { wow: true }, })) @@ -89,7 +90,7 @@ describe('useQuery', () => { it('TData should have undefined in the union when initialData is NOT provided', () => { const { data } = useQuery(() => ({ - queryKey: ['key'], + queryKey: queryKey(), queryFn: () => ({ wow: true }), })) diff --git a/packages/solid-query/src/__tests__/useQuery.test.tsx b/packages/solid-query/src/__tests__/useQuery.test.tsx index d001fbaf5d..904f82e0c4 100644 --- a/packages/solid-query/src/__tests__/useQuery.test.tsx +++ b/packages/solid-query/src/__tests__/useQuery.test.tsx @@ -5047,6 +5047,7 @@ describe('useQuery', () => { }) it('should refetch when changed enabled to true in error state', async () => { + const key = queryKey() const queryFn = vi.fn<(...args: Array) => unknown>() queryFn.mockImplementation(() => sleep(10).then(() => Promise.reject(new Error('Suspense Error Bingo'))), @@ -5054,7 +5055,7 @@ describe('useQuery', () => { function Page(props: { enabled: boolean }) { const state = useQuery(() => ({ - queryKey: ['key'], + queryKey: key, queryFn, enabled: props.enabled, retry: false,