diff --git a/eslint.config.js b/eslint.config.js index f156cd2e9c2..3b5cd36f26e 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -39,6 +39,7 @@ export default [ ], '@typescript-eslint/no-empty-function': 'off', '@typescript-eslint/no-unsafe-function-type': 'off', + '@typescript-eslint/require-await': 'error', 'no-case-declarations': 'off', }, }, 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 f07e0ded244..93bda3204ea 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 @@ -23,7 +23,7 @@ describe('injectInfiniteQuery', () => { vi.useRealTimers() }) - test('should narrow type after isSuccess', async () => { + test('should narrow type after isSuccess', () => { const query = TestBed.runInInjectionContext(() => { return injectInfiniteQuery(() => ({ queryKey: ['infiniteQuery'], diff --git a/packages/query-broadcast-client-experimental/src/__tests__/index.test.ts b/packages/query-broadcast-client-experimental/src/__tests__/index.test.ts index 763a7edd58e..6e09d8a86e2 100644 --- a/packages/query-broadcast-client-experimental/src/__tests__/index.test.ts +++ b/packages/query-broadcast-client-experimental/src/__tests__/index.test.ts @@ -12,7 +12,7 @@ describe('broadcastQueryClient', () => { queryCache = queryClient.getQueryCache() }) - it('should subscribe to the query cache', async () => { + it('should subscribe to the query cache', () => { broadcastQueryClient({ queryClient, broadcastChannel: 'test_channel', @@ -20,7 +20,7 @@ describe('broadcastQueryClient', () => { expect(queryCache.hasListeners()).toBe(true) }) - it('should not have any listeners after cleanup', async () => { + it('should not have any listeners after cleanup', () => { const unsubscribe = broadcastQueryClient({ queryClient, broadcastChannel: 'test_channel', diff --git a/packages/query-codemods/eslint.config.js b/packages/query-codemods/eslint.config.js index 19a16c3c1e8..aa13b1cd93e 100644 --- a/packages/query-codemods/eslint.config.js +++ b/packages/query-codemods/eslint.config.js @@ -1,6 +1,5 @@ // @ts-check -import vitest from '@vitest/eslint-plugin' import rootConfig from './root.eslint.config.js' export default [ @@ -9,6 +8,7 @@ export default [ rules: { 'cspell/spellchecker': 'off', '@typescript-eslint/no-unnecessary-condition': 'off', + '@typescript-eslint/require-await': 'off', 'import/no-duplicates': 'off', 'import/no-unresolved': 'off', 'import/order': 'off', diff --git a/packages/query-core/src/__tests__/queryObserver.test.tsx b/packages/query-core/src/__tests__/queryObserver.test.tsx index 6b8b70ace9f..6d20eb2430b 100644 --- a/packages/query-core/src/__tests__/queryObserver.test.tsx +++ b/packages/query-core/src/__tests__/queryObserver.test.tsx @@ -31,7 +31,7 @@ describe('queryObserver', () => { vi.useRealTimers() }) - test('should trigger a fetch when subscribed', async () => { + test('should trigger a fetch when subscribed', () => { const key = queryKey() const queryFn = vi .fn<(...args: Array) => string>() diff --git a/packages/react-query/src/__tests__/useQuery.test-d.tsx b/packages/react-query/src/__tests__/useQuery.test-d.tsx index fd5e265b748..7e99666bebc 100644 --- a/packages/react-query/src/__tests__/useQuery.test-d.tsx +++ b/packages/react-query/src/__tests__/useQuery.test-d.tsx @@ -152,7 +152,7 @@ describe('useQuery', () => { ) expectTypeOf(testFuncStyle.data).toEqualTypeOf() - it('should return the correct states for a successful query', async () => { + it('should return the correct states for a successful query', () => { const state = useQuery({ queryKey: key, queryFn: () => Promise.resolve('test'), diff --git a/packages/react-query/src/__tests__/useQuery.test.tsx b/packages/react-query/src/__tests__/useQuery.test.tsx index 3635b668bf7..02bd28d9297 100644 --- a/packages/react-query/src/__tests__/useQuery.test.tsx +++ b/packages/react-query/src/__tests__/useQuery.test.tsx @@ -608,7 +608,7 @@ describe('useQuery', () => { expect(states[1]).toMatchObject({ data: 'test' }) }) - it('should not fetch when refetchOnMount is false and data has been fetched already', async () => { + it('should not fetch when refetchOnMount is false and data has been fetched already', () => { const key = queryKey() const states: Array> = [] @@ -1106,7 +1106,7 @@ describe('useQuery', () => { }) }) - it('should not refetch disabled query when invalidated with invalidateQueries', async () => { + it('should not refetch disabled query when invalidated with invalidateQueries', () => { const key = queryKey() const states: Array> = [] let count = 0 diff --git a/packages/react-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx b/packages/react-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx index 398b7515cdd..46d7747df23 100644 --- a/packages/react-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx +++ b/packages/react-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx @@ -46,4 +46,72 @@ describe('useSuspenseInfiniteQuery', () => { ) consoleErrorSpy.mockRestore() }) + + it('should log an error when skipToken is used in development environment', () => { + const envCopy = process.env.NODE_ENV + process.env.NODE_ENV = 'development' + + const consoleErrorSpy = vi + .spyOn(console, 'error') + .mockImplementation(() => undefined) + const key = queryKey() + + function Page() { + useSuspenseInfiniteQuery({ + queryKey: key, + queryFn: skipToken as any, + initialPageParam: 1, + getNextPageParam: () => 1, + }) + + return null + } + + renderWithClient( + queryClient, + + + , + ) + + expect(consoleErrorSpy).toHaveBeenCalledWith( + 'skipToken is not allowed for useSuspenseInfiniteQuery', + ) + + consoleErrorSpy.mockRestore() + process.env.NODE_ENV = envCopy + }) + + it('should not log an error when skipToken is used in production environment', () => { + const envCopy = process.env.NODE_ENV + process.env.NODE_ENV = 'production' + + const consoleErrorSpy = vi + .spyOn(console, 'error') + .mockImplementation(() => undefined) + const key = queryKey() + + function Page() { + useSuspenseInfiniteQuery({ + queryKey: key, + queryFn: skipToken as any, + initialPageParam: 1, + getNextPageParam: () => 1, + }) + + return null + } + + renderWithClient( + queryClient, + + + , + ) + + expect(consoleErrorSpy).not.toHaveBeenCalled() + + consoleErrorSpy.mockRestore() + process.env.NODE_ENV = envCopy + }) }) diff --git a/packages/react-query/src/__tests__/useSuspenseQueries.test.tsx b/packages/react-query/src/__tests__/useSuspenseQueries.test.tsx index 64f09fb800e..4b7f7dad93f 100644 --- a/packages/react-query/src/__tests__/useSuspenseQueries.test.tsx +++ b/packages/react-query/src/__tests__/useSuspenseQueries.test.tsx @@ -713,4 +713,76 @@ describe('useSuspenseQueries 2', () => { ) consoleErrorSpy.mockRestore() }) + + it('should log an error when skipToken is used in development environment', () => { + const envCopy = process.env.NODE_ENV + process.env.NODE_ENV = 'development' + + const consoleErrorSpy = vi + .spyOn(console, 'error') + .mockImplementation(() => undefined) + const key = queryKey() + + function Page() { + useSuspenseQueries({ + queries: [ + { + queryKey: key, + queryFn: skipToken as any, + }, + ], + }) + + return null + } + + renderWithClient( + queryClient, + + + , + ) + + expect(consoleErrorSpy).toHaveBeenCalledWith( + 'skipToken is not allowed for useSuspenseQueries', + ) + + consoleErrorSpy.mockRestore() + process.env.NODE_ENV = envCopy + }) + + it('should not log an error when skipToken is used in production environment', () => { + const envCopy = process.env.NODE_ENV + process.env.NODE_ENV = 'production' + + const consoleErrorSpy = vi + .spyOn(console, 'error') + .mockImplementation(() => undefined) + const key = queryKey() + + function Page() { + useSuspenseQueries({ + queries: [ + { + queryKey: key, + queryFn: skipToken as any, + }, + ], + }) + + return null + } + + renderWithClient( + queryClient, + + + , + ) + + expect(consoleErrorSpy).not.toHaveBeenCalled() + + consoleErrorSpy.mockRestore() + process.env.NODE_ENV = envCopy + }) }) diff --git a/packages/react-query/src/__tests__/useSuspenseQuery.test.tsx b/packages/react-query/src/__tests__/useSuspenseQuery.test.tsx index 3ea24a93264..27d3d5a5ca7 100644 --- a/packages/react-query/src/__tests__/useSuspenseQuery.test.tsx +++ b/packages/react-query/src/__tests__/useSuspenseQuery.test.tsx @@ -967,4 +967,68 @@ describe('useSuspenseQuery', () => { expect(count).toBeGreaterThanOrEqual(3) }) + + it('should log an error when skipToken is used in development environment', () => { + const envCopy = process.env.NODE_ENV + process.env.NODE_ENV = 'development' + + const consoleErrorSpy = vi + .spyOn(console, 'error') + .mockImplementation(() => undefined) + const key = queryKey() + + function Page() { + useSuspenseQuery({ + queryKey: key, + queryFn: skipToken as any, + }) + + return null + } + + renderWithClient( + queryClient, + + + , + ) + + expect(consoleErrorSpy).toHaveBeenCalledWith( + 'skipToken is not allowed for useSuspenseQuery', + ) + + consoleErrorSpy.mockRestore() + process.env.NODE_ENV = envCopy + }) + + it('should not log an error when skipToken is used in production environment', () => { + const envCopy = process.env.NODE_ENV + process.env.NODE_ENV = 'production' + + const consoleErrorSpy = vi + .spyOn(console, 'error') + .mockImplementation(() => undefined) + const key = queryKey() + + function Page() { + useSuspenseQuery({ + queryKey: key, + queryFn: skipToken as any, + }) + + return null + } + + renderWithClient( + queryClient, + + + , + ) + + expect(consoleErrorSpy).not.toHaveBeenCalled() + + consoleErrorSpy.mockRestore() + process.env.NODE_ENV = envCopy + }) })