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 e53af1ae78..d50b8c6b81 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 @@ -166,7 +166,7 @@ describe('infiniteQueryOptions', () => { ) }) - it('allow optional initialData function', () => { + it('should allow optional initialData function', () => { const key = queryKey() const initialData: { example: boolean } | undefined = { example: true } const queryOptions = infiniteQueryOptions({ @@ -185,7 +185,7 @@ describe('infiniteQueryOptions', () => { >() }) - it('allow optional initialData object', () => { + it('should allow optional initialData object', () => { const key = queryKey() const initialData: { example: boolean } | undefined = { example: true } const queryOptions = infiniteQueryOptions({ 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 fbaea8ca00..45c1f6bc34 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 @@ -64,7 +64,7 @@ describe('injectInfiniteQuery', () => { }) describe('injection context', () => { - it('throws NG0203 with descriptive error outside injection context', () => { + it('should throw NG0203 with descriptive error outside injection context', () => { const key = queryKey() expect(() => { injectInfiniteQuery(() => ({ @@ -77,7 +77,7 @@ describe('injectInfiniteQuery', () => { }).toThrow(/NG0203(.*?)injectInfiniteQuery/) }) - it('can be used outside injection context when passing an injector', () => { + it('should be usable outside injection context when passing an injector', () => { const key = queryKey() const query = injectInfiniteQuery( () => ({ 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 97d8651b19..f1d2861ab1 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 @@ -28,7 +28,7 @@ describe('injectIsFetching', () => { vi.useRealTimers() }) - it('Returns number of fetching queries', async () => { + it('should return the number of fetching queries', async () => { const key = queryKey() const isFetching = TestBed.runInInjectionContext(() => { injectQuery(() => ({ @@ -46,13 +46,13 @@ describe('injectIsFetching', () => { }) describe('injection context', () => { - it('throws NG0203 with descriptive error outside injection context', () => { + it('should throw NG0203 with descriptive error outside injection context', () => { expect(() => { injectIsFetching() }).toThrow(/NG0203(.*?)injectIsFetching/) }) - it('can be used outside injection context when passing an injector', () => { + it('should be usable outside injection context when passing an injector', () => { expect( injectIsFetching(undefined, { injector: TestBed.inject(Injector), 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 652ad4031c..8433fef501 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 @@ -52,13 +52,13 @@ describe('injectIsMutating', () => { }) describe('injection context', () => { - it('throws NG0203 with descriptive error outside injection context', () => { + it('should throw NG0203 with descriptive error outside injection context', () => { expect(() => { injectIsMutating() }).toThrow(/NG0203(.*?)injectIsMutating/) }) - it('can be used outside injection context when passing an injector', () => { + it('should be usable outside injection context when passing an injector', () => { expect( injectIsMutating(undefined, { injector: TestBed.inject(Injector), diff --git a/packages/angular-query-experimental/src/__tests__/inject-is-restoring.test.ts b/packages/angular-query-experimental/src/__tests__/inject-is-restoring.test.ts index 44b5df6990..0b74019b3a 100644 --- a/packages/angular-query-experimental/src/__tests__/inject-is-restoring.test.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-is-restoring.test.ts @@ -1,5 +1,5 @@ import { TestBed } from '@angular/core/testing' -import { describe, expect, it } from 'vitest' +import { beforeEach, describe, expect, it } from 'vitest' import { Injector, provideZonelessChangeDetection, signal } from '@angular/core' import { QueryClient, @@ -11,16 +11,17 @@ import { describe('injectIsRestoring', () => { let queryClient: QueryClient - it('returns false by default when provideIsRestoring is not used', () => { + beforeEach(() => { queryClient = new QueryClient() - TestBed.configureTestingModule({ providers: [ provideZonelessChangeDetection(), provideTanStackQuery(queryClient), ], }) + }) + it('should return false by default when provideIsRestoring is not used', () => { const isRestoring = TestBed.runInInjectionContext(() => { return injectIsRestoring() }) @@ -28,16 +29,11 @@ describe('injectIsRestoring', () => { expect(isRestoring()).toBe(false) }) - it('returns provided signal value when provideIsRestoring is used', () => { - queryClient = new QueryClient() + it('should return the provided signal value when provideIsRestoring is used', () => { const restoringSignal = signal(true) TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery(queryClient), - provideIsRestoring(restoringSignal.asReadonly()), - ], + providers: [provideIsRestoring(restoringSignal.asReadonly())], }) const isRestoring = TestBed.runInInjectionContext(() => { @@ -47,16 +43,7 @@ describe('injectIsRestoring', () => { expect(isRestoring()).toBe(true) }) - it('can be used outside injection context when passing an injector', () => { - queryClient = new QueryClient() - - TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery(queryClient), - ], - }) - + it('should be usable outside injection context when passing an injector', () => { const isRestoring = injectIsRestoring({ injector: TestBed.inject(Injector), }) @@ -64,7 +51,7 @@ describe('injectIsRestoring', () => { expect(isRestoring()).toBe(false) }) - it('throws NG0203 with descriptive error outside injection context', () => { + it('should throw NG0203 with descriptive error outside injection context', () => { expect(() => { injectIsRestoring() }).toThrow(/NG0203(.*?)injectIsRestoring/) 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 2808f92c22..4eee7699ae 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 @@ -59,7 +59,7 @@ describe('injectMutationState', () => { expect(mutationState()).toEqual([variables]) }) - it('reactive options should update injectMutationState', () => { + it('should update injectMutationState when reactive options change', () => { const mutationKey1 = queryKey() const mutationKey2 = queryKey() const variables1 = 'foo123' @@ -179,13 +179,13 @@ describe('injectMutationState', () => { }) describe('injection context', () => { - it('throws NG0203 with descriptive error outside injection context', () => { + it('should throw NG0203 with descriptive error outside injection context', () => { expect(() => { injectMutationState() }).toThrow(/NG0203(.*?)injectMutationState/) }) - it('can be used outside injection context when passing an injector', () => { + it('should be usable outside injection context when passing an injector', () => { const injector = TestBed.inject(Injector) expect( injectMutationState(undefined, { 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 5a0bfb88c2..5d9c2e93c3 100644 --- a/packages/angular-query-experimental/src/__tests__/inject-mutation.test.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-mutation.test.ts @@ -114,7 +114,7 @@ describe('injectMutation', () => { }) }) - it('reactive options should update mutation', () => { + it('should update mutation when reactive options change', () => { const mutationCache = queryClient.getMutationCache() // Signal will be updated before the mutation is called // this test confirms that the mutation uses the updated value @@ -473,7 +473,7 @@ describe('injectMutation', () => { }) describe('injection context', () => { - it('throws NG0203 with descriptive error outside injection context', () => { + it('should throw NG0203 with descriptive error outside injection context', () => { const key = queryKey() expect(() => { injectMutation(() => ({ @@ -483,7 +483,7 @@ describe('injectMutation', () => { }).toThrow(/NG0203(.*?)injectMutation/) }) - it('can be used outside injection context when passing an injector', () => { + it('should be usable outside injection context when passing an injector', () => { const key = queryKey() expect(() => { injectMutation( @@ -536,14 +536,6 @@ describe('injectMutation', () => { }) it('should handle synchronous mutation with retry', async () => { - TestBed.resetTestingModule() - TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery(queryClient), - ], - }) - const app = TestBed.inject(ApplicationRef) let attemptCount = 0 @@ -586,14 +578,6 @@ describe('injectMutation', () => { }) it('should handle multiple synchronous mutations on same key', async () => { - TestBed.resetTestingModule() - TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery(queryClient), - ], - }) - const app = TestBed.inject(ApplicationRef) let callCount = 0 @@ -640,14 +624,6 @@ describe('injectMutation', () => { }) it('should handle synchronous mutation with optimistic updates', async () => { - TestBed.resetTestingModule() - TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery(queryClient), - ], - }) - const app = TestBed.inject(ApplicationRef) const testQueryKey = queryKey() let onMutateCalled = false @@ -692,14 +668,6 @@ describe('injectMutation', () => { }) it('should handle synchronous mutation cancellation', async () => { - TestBed.resetTestingModule() - TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery(queryClient), - ], - }) - const app = TestBed.inject(ApplicationRef) const key = queryKey() 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 1248c386b6..71fc4ad758 100644 --- a/packages/angular-query-experimental/src/__tests__/inject-queries.test.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-queries.test.ts @@ -11,24 +11,24 @@ import { queryKey, sleep } from '@tanstack/query-test-utils' import { QueryClient, provideIsRestoring, provideTanStackQuery } from '..' import { injectQueries } from '../inject-queries' -let queryClient: QueryClient - -beforeEach(() => { - vi.useFakeTimers() - queryClient = new QueryClient() - TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery(queryClient), - ], +describe('injectQueries', () => { + let queryClient: QueryClient + + beforeEach(() => { + vi.useFakeTimers() + queryClient = new QueryClient() + TestBed.configureTestingModule({ + providers: [ + provideZonelessChangeDetection(), + provideTanStackQuery(queryClient), + ], + }) }) -}) -afterEach(() => { - vi.useRealTimers() -}) + afterEach(() => { + vi.useRealTimers() + }) -describe('injectQueries', () => { it('should return the correct states', async () => { const key1 = queryKey() const key2 = queryKey() @@ -143,13 +143,8 @@ describe('injectQueries', () => { const queryFn1 = vi.fn().mockImplementation(() => sleep(10).then(() => 1)) const queryFn2 = vi.fn().mockImplementation(() => sleep(10).then(() => 2)) - TestBed.resetTestingModule() TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery(queryClient), - provideIsRestoring(signal(true).asReadonly()), - ], + providers: [provideIsRestoring(signal(true).asReadonly())], }) const queries = TestBed.runInInjectionContext(() => 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 652081c3c2..6d33aa86a7 100644 --- a/packages/angular-query-experimental/src/__tests__/inject-query.test.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-query.test.ts @@ -38,6 +38,7 @@ import type { CreateQueryOptions, OmitKeyof, QueryFunction } from '..' describe('injectQuery', () => { let queryCache: QueryCache let queryClient: QueryClient + beforeEach(() => { vi.useFakeTimers() queryCache = new QueryCache() @@ -566,13 +567,8 @@ describe('injectQuery', () => { .fn() .mockImplementation(() => sleep(10).then(() => 'data')) - TestBed.resetTestingModule() TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery(queryClient), - provideIsRestoring(signal(true).asReadonly()), - ], + providers: [provideIsRestoring(signal(true).asReadonly())], }) const query = TestBed.runInInjectionContext(() => @@ -597,7 +593,7 @@ describe('injectQuery', () => { }) describe('injection context', () => { - it('throws NG0203 with descriptive error outside injection context', () => { + it('should throw NG0203 with descriptive error outside injection context', () => { const key = queryKey() expect(() => { injectQuery(() => ({ @@ -607,7 +603,7 @@ describe('injectQuery', () => { }).toThrow(/NG0203(.*?)injectQuery/) }) - it('can be used outside injection context when passing an injector', () => { + it('should be usable outside injection context when passing an injector', () => { const key = queryKey() const query = injectQuery( () => ({ @@ -645,14 +641,8 @@ describe('injectQuery', () => { }) it('should complete HttpClient-based queries before whenStable() resolves', async () => { - TestBed.resetTestingModule() TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery(queryClient), - provideHttpClient(), - provideHttpClientTesting(), - ], + providers: [provideHttpClient(), provideHttpClientTesting()], }) const app = TestBed.inject(ApplicationRef) @@ -691,14 +681,6 @@ describe('injectQuery', () => { }) it('should handle synchronous queryFn with staleTime', async () => { - TestBed.resetTestingModule() - TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery(queryClient), - ], - }) - const app = TestBed.inject(ApplicationRef) let callCount = 0 @@ -735,14 +717,6 @@ describe('injectQuery', () => { }) it('should handle enabled/disabled transitions with synchronous queryFn', async () => { - TestBed.resetTestingModule() - TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery(queryClient), - ], - }) - const app = TestBed.inject(ApplicationRef) const enabledSignal = signal(false) let callCount = 0 @@ -777,14 +751,6 @@ describe('injectQuery', () => { }) it('should handle query invalidation with synchronous data', async () => { - TestBed.resetTestingModule() - TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery(queryClient), - ], - }) - const app = TestBed.inject(ApplicationRef) const testKey = queryKey() let callCount = 0 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 abb0752b9b..0bdd109a4a 100644 --- a/packages/angular-query-experimental/src/__tests__/pending-tasks.test.ts +++ b/packages/angular-query-experimental/src/__tests__/pending-tasks.test.ts @@ -458,14 +458,8 @@ describe('PendingTasks Integration', () => { describe('HttpClient Integration', () => { beforeEach(() => { - TestBed.resetTestingModule() TestBed.configureTestingModule({ - providers: [ - provideZonelessChangeDetection(), - provideTanStackQuery(queryClient), - provideHttpClient(), - provideHttpClientTesting(), - ], + providers: [provideHttpClient(), provideHttpClientTesting()], }) }) diff --git a/packages/angular-query-experimental/src/__tests__/signal-proxy.test.ts b/packages/angular-query-experimental/src/__tests__/signal-proxy.test.ts index b7ad207fb6..cebcd7b82b 100644 --- a/packages/angular-query-experimental/src/__tests__/signal-proxy.test.ts +++ b/packages/angular-query-experimental/src/__tests__/signal-proxy.test.ts @@ -16,12 +16,12 @@ describe('signalProxy', () => { expect(isSignal(proxy.fn)).toBe(false) }) - it('supports "in" operator', () => { + it('should support "in" operator', () => { expect('baz' in proxy).toBe(true) expect('foo' in proxy).toBe(false) }) - it('supports "Object.keys"', () => { + it('should support "Object.keys"', () => { expect(Object.keys(proxy)).toEqual(['fn', 'baz']) }) }) diff --git a/packages/angular-query-experimental/src/__tests__/with-devtools.test.ts b/packages/angular-query-experimental/src/__tests__/with-devtools.test.ts index 81bc73c4be..92685d9371 100644 --- a/packages/angular-query-experimental/src/__tests__/with-devtools.test.ts +++ b/packages/angular-query-experimental/src/__tests__/with-devtools.test.ts @@ -153,6 +153,33 @@ describe('withDevtools feature', () => { }, ) + it("should throw 'No QueryClient found' when 'loadDevtools' is 'true' and no 'QueryClient' is provided", async () => { + const consoleErrorSpy = vi + .spyOn(console, 'error') + .mockImplementation(() => undefined) + + TestBed.configureTestingModule({ + providers: [ + provideZonelessChangeDetection(), + withDevtools(() => ({ + loadDevtools: true, + })).ɵproviders, + ], + }) + + TestBed.inject(ENVIRONMENT_INITIALIZER) + TestBed.tick() + await vi.dynamicImportSettled() + + expect(mockTanstackQueryDevtools).not.toHaveBeenCalled() + expect(consoleErrorSpy).toHaveBeenCalledWith( + 'Install @tanstack/query-devtools or reinstall without --omit=optional.', + expect.objectContaining({ message: 'No QueryClient found' }), + ) + + consoleErrorSpy.mockRestore() + }) + it('should not continue loading devtools after injector is destroyed', async () => { TestBed.configureTestingModule({ providers: [ 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 093efb825a..1f9bd61419 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 @@ -18,14 +18,6 @@ import type { Persister, } from '@tanstack/query-persist-client-core' -beforeEach(() => { - vi.useFakeTimers() -}) - -afterEach(() => { - vi.useRealTimers() -}) - const createMockPersister = (): Persister => { let storedState: PersistedClient | undefined @@ -62,7 +54,15 @@ const createMockErrorPersister = ( } describe('withPersistQueryClient', () => { - it('restores cache from persister', async () => { + beforeEach(() => { + vi.useFakeTimers() + }) + + afterEach(() => { + vi.useRealTimers() + }) + + it('should restore cache from persister', async () => { const key = queryKey() const states: Array<{ status: string diff --git a/packages/query-persist-client-core/src/__tests__/createPersister.test.ts b/packages/query-persist-client-core/src/__tests__/createPersister.test.ts index bc630b8c73..b8b1de807b 100644 --- a/packages/query-persist-client-core/src/__tests__/createPersister.test.ts +++ b/packages/query-persist-client-core/src/__tests__/createPersister.test.ts @@ -436,7 +436,7 @@ describe('createPersister', () => { }) describe('persistQuery', () => { - it('Should properly persiste basic query', async () => { + it('Should properly persist basic query', async () => { const storage = getFreshStorage() const { persister, query, queryHash, queryKey, storageKey } = setupPersister(['foo'], { @@ -458,7 +458,7 @@ describe('createPersister', () => { }) }) - it('Should skip persistance if storage is not provided', async () => { + it('Should skip persistence if storage is not provided', async () => { const serializeMock = vi.fn() const { persister, query } = setupPersister(['foo'], { storage: null, @@ -473,7 +473,7 @@ describe('createPersister', () => { }) describe('persistQueryByKey', () => { - it('Should skip persistance if storage is not provided', async () => { + it('Should skip persistence if storage is not provided', async () => { const serializeMock = vi.fn() const { persister, client, queryKey } = setupPersister(['foo'], { storage: null, @@ -486,7 +486,7 @@ describe('createPersister', () => { expect(serializeMock).toHaveBeenCalledTimes(0) }) - it('should skip persistance if query was not found', async () => { + it('should skip persistence if query was not found', async () => { const serializeMock = vi.fn() const storage = getFreshStorage() const { client, persister, queryKey } = setupPersister(['foo'], { @@ -500,7 +500,7 @@ describe('createPersister', () => { expect(serializeMock).toHaveBeenCalledTimes(0) }) - it('Should properly persiste basic query', async () => { + it('Should properly persist basic query', async () => { const storage = getFreshStorage() const { persister, client, queryHash, queryKey, storageKey } = setupPersister(['foo'], { diff --git a/packages/react-query/src/__tests__/useQuery.test.tsx b/packages/react-query/src/__tests__/useQuery.test.tsx index 71cda44e37..d0c8dae5ae 100644 --- a/packages/react-query/src/__tests__/useQuery.test.tsx +++ b/packages/react-query/src/__tests__/useQuery.test.tsx @@ -6846,7 +6846,7 @@ describe('useQuery', () => { const { status, error } = useQuery({ queryKey: key, queryFn, - throwOnError: (error) => error.message.includes('404'), + throwOnError: (err) => err.message.includes('404'), retryOnMount: true, staleTime: Infinity, retry: false, diff --git a/packages/vue-query/src/__tests__/queryClient.test-d.ts b/packages/vue-query/src/__tests__/queryClient.test-d.ts index 9af6d20307..cd3af0d561 100644 --- a/packages/vue-query/src/__tests__/queryClient.test-d.ts +++ b/packages/vue-query/src/__tests__/queryClient.test-d.ts @@ -5,25 +5,25 @@ import type { DataTag, InfiniteData } from '@tanstack/query-core' describe('getQueryData', () => { it('should be typed if key is tagged', () => { - const queryKey = ['key'] as DataTag, number> + const key = ['key'] as DataTag, number> const queryClient = new QueryClient() - const data = queryClient.getQueryData(queryKey) + const data = queryClient.getQueryData(key) expectTypeOf(data).toEqualTypeOf() }) it('should infer unknown if key is not tagged', () => { - const queryKey = ['key'] as const + const key = ['key'] as const const queryClient = new QueryClient() - const data = queryClient.getQueryData(queryKey) + const data = queryClient.getQueryData(key) expectTypeOf(data).toEqualTypeOf() }) it('should infer passed generic if passed', () => { - const queryKey = ['key'] as const + const key = ['key'] as const const queryClient = new QueryClient() - const data = queryClient.getQueryData(queryKey) + const data = queryClient.getQueryData(key) expectTypeOf(data).toEqualTypeOf() }) @@ -38,9 +38,9 @@ describe('getQueryData', () => { describe('setQueryData', () => { it('updater should be typed if key is tagged', () => { - const queryKey = ['key'] as DataTag, number> + const key = ['key'] as DataTag, number> const queryClient = new QueryClient() - const data = queryClient.setQueryData(queryKey, (prev) => { + const data = queryClient.setQueryData(key, (prev) => { expectTypeOf(prev).toEqualTypeOf() return prev }) @@ -48,24 +48,24 @@ describe('setQueryData', () => { }) it('value should be typed if key is tagged', () => { - const queryKey = ['key'] as DataTag, number> + const key = ['key'] as DataTag, number> const queryClient = new QueryClient() // @ts-expect-error value should be a number - queryClient.setQueryData(queryKey, '1') + queryClient.setQueryData(key, '1') // @ts-expect-error value should be a number - queryClient.setQueryData(queryKey, () => '1') + queryClient.setQueryData(key, () => '1') - const data = queryClient.setQueryData(queryKey, 1) + const data = queryClient.setQueryData(key, 1) expectTypeOf(data).toEqualTypeOf() }) it('should infer unknown for updater if key is not tagged', () => { - const queryKey = ['key'] as const + const key = ['key'] as const const queryClient = new QueryClient() - const data = queryClient.setQueryData(queryKey, (prev) => { + const data = queryClient.setQueryData(key, (prev) => { expectTypeOf(prev).toEqualTypeOf() return prev }) @@ -73,17 +73,17 @@ describe('setQueryData', () => { }) it('should infer unknown for value if key is not tagged', () => { - const queryKey = ['key'] as const + const key = ['key'] as const const queryClient = new QueryClient() - const data = queryClient.setQueryData(queryKey, 'foo') + const data = queryClient.setQueryData(key, 'foo') expectTypeOf(data).toEqualTypeOf() }) it('should infer passed generic if passed', () => { - const queryKey = ['key'] as const + const key = ['key'] as const const queryClient = new QueryClient() - const data = queryClient.setQueryData(queryKey, (prev) => { + const data = queryClient.setQueryData(key, (prev) => { expectTypeOf(prev).toEqualTypeOf() return prev }) @@ -91,21 +91,21 @@ describe('setQueryData', () => { }) it('should infer passed generic for value', () => { - const queryKey = ['key'] as const + const key = ['key'] as const const queryClient = new QueryClient() - const data = queryClient.setQueryData(queryKey, 'foo') + const data = queryClient.setQueryData(key, 'foo') expectTypeOf(data).toEqualTypeOf() }) it('should preserve updater parameter type inference when used in functions with explicit return types', () => { - const queryKey = ['key'] as DataTag, number> + const key = ['key'] as DataTag, number> const queryClient = new QueryClient() // Simulate usage inside a function with explicit return type // The outer function returns 'unknown' but this shouldn't affect the updater's type inference ;(() => - queryClient.setQueryData(queryKey, (data) => { + queryClient.setQueryData(key, (data) => { expectTypeOf(data).toEqualTypeOf() return data })) satisfies () => unknown