diff --git a/oxlint.config.ts b/oxlint.config.ts index a1befe1145..484a66e3cb 100644 --- a/oxlint.config.ts +++ b/oxlint.config.ts @@ -313,6 +313,7 @@ export default defineConfig({ 'vitest/prefer-import-in-mock': 'error', 'vitest/prefer-importing-vitest-globals': 'error', 'vitest/prefer-mock-promise-shorthand': 'error', + 'vitest/prefer-mock-return-shorthand': 'error', 'vitest/prefer-snapshot-hint': 'error', 'vitest/prefer-spy-on': 'error', 'vitest/prefer-strict-boolean-matchers': 'error', 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 2e3fc38d01..923c42910d 100644 --- a/packages/angular-query-experimental/src/__tests__/inject-queries.test.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-queries.test.ts @@ -180,8 +180,8 @@ describe('injectQueries', () => { it('should not fetch for the duration of the restoring period when isRestoring is true', async () => { const key1 = queryKey() const key2 = queryKey() - const queryFn1 = vi.fn().mockImplementation(() => sleep(10).then(() => 1)) - const queryFn2 = vi.fn().mockImplementation(() => sleep(10).then(() => 2)) + const queryFn1 = vi.fn(() => sleep(10).then(() => 1)) + const queryFn2 = vi.fn(() => sleep(10).then(() => 2)) TestBed.configureTestingModule({ providers: [provideIsRestoring(signal(true).asReadonly())], 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 63f8d8ecad..ab6dcfec2f 100644 --- a/packages/angular-query-experimental/src/__tests__/inject-query.test.ts +++ b/packages/angular-query-experimental/src/__tests__/inject-query.test.ts @@ -274,9 +274,7 @@ describe('injectQuery', () => { })) }) - const dependentQueryFn = vi - .fn() - .mockImplementation(() => sleep(1000).then(() => 'Some data')) + const dependentQueryFn = vi.fn(() => sleep(1000).then(() => 'Some data')) const query2 = TestBed.runInInjectionContext(() => { return injectQuery( @@ -453,9 +451,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 queryFn = vi - .fn() - .mockImplementation(() => sleep(10).then(() => 'data')) + const queryFn = vi.fn(() => sleep(10).then(() => 'data')) TestBed.configureTestingModule({ providers: [provideIsRestoring(signal(true).asReadonly())], 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 a717d9262d..7909c3c8d3 100644 --- a/packages/angular-query-experimental/src/__tests__/with-devtools.test.ts +++ b/packages/angular-query-experimental/src/__tests__/with-devtools.test.ts @@ -158,7 +158,7 @@ describe('withDevtools feature', () => { it("should throw 'No QueryClient found' when 'loadDevtools' is 'true' and no 'QueryClient' is provided", async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) 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 0be09baf61..e99d3482b0 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 @@ -396,7 +396,7 @@ describe('withPersistQueryClient', () => { const key = queryKey() const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const queryClient = new QueryClient() const removeClient = vi.fn() const [error, persister] = createMockErrorPersister(removeClient) diff --git a/packages/preact-query/src/__tests__/QueryClientProvider.test.tsx b/packages/preact-query/src/__tests__/QueryClientProvider.test.tsx index b94fb135db..fafd1021df 100644 --- a/packages/preact-query/src/__tests__/QueryClientProvider.test.tsx +++ b/packages/preact-query/src/__tests__/QueryClientProvider.test.tsx @@ -148,7 +148,7 @@ describe('QueryClientProvider', () => { it('should throw an error if no query client has been set', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { useQueryClient() diff --git a/packages/preact-query/src/__tests__/QueryResetErrorBoundary.test.tsx b/packages/preact-query/src/__tests__/QueryResetErrorBoundary.test.tsx index 43c1e9df14..24ec18d741 100644 --- a/packages/preact-query/src/__tests__/QueryResetErrorBoundary.test.tsx +++ b/packages/preact-query/src/__tests__/QueryResetErrorBoundary.test.tsx @@ -35,7 +35,7 @@ describe('QueryErrorResetBoundary', () => { it('should retry fetch if the reset error boundary has been reset', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let succeed = false @@ -96,7 +96,7 @@ describe('QueryErrorResetBoundary', () => { it('should not throw error if query is disabled', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let succeed = false @@ -163,7 +163,7 @@ describe('QueryErrorResetBoundary', () => { it('should not throw error if query is disabled, and refetch if query becomes enabled again', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() @@ -231,7 +231,7 @@ describe('QueryErrorResetBoundary', () => { it('should throw error if query is disabled and manually refetch', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() @@ -299,7 +299,7 @@ describe('QueryErrorResetBoundary', () => { it('should not retry fetch if the reset error boundary has not been reset', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() @@ -360,7 +360,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 () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() @@ -424,7 +424,7 @@ describe('QueryErrorResetBoundary', () => { it('should not retry fetch if the reset error boundary has not been reset after a previous reset', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() @@ -506,7 +506,7 @@ describe('QueryErrorResetBoundary', () => { it('should throw again on error after the reset error boundary has been reset', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let fetchCount = 0 @@ -572,7 +572,7 @@ describe('QueryErrorResetBoundary', () => { it('should never render the component while the query is in error state', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let fetchCount = 0 @@ -647,7 +647,7 @@ describe('QueryErrorResetBoundary', () => { it('should render children', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { return ( @@ -672,7 +672,7 @@ describe('QueryErrorResetBoundary', () => { it('should show error boundary when using tracked queries even though we do not track the error field', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() @@ -736,7 +736,7 @@ describe('QueryErrorResetBoundary', () => { it('should retry fetch if the reset error boundary has been reset', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let succeed = false @@ -803,7 +803,7 @@ describe('QueryErrorResetBoundary', () => { const key = queryKey() const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) let succeed = false diff --git a/packages/preact-query/src/__tests__/ssr-hydration.test.tsx b/packages/preact-query/src/__tests__/ssr-hydration.test.tsx index 5ef59b66d4..7ba27d3852 100644 --- a/packages/preact-query/src/__tests__/ssr-hydration.test.tsx +++ b/packages/preact-query/src/__tests__/ssr-hydration.test.tsx @@ -51,7 +51,7 @@ describe('Server side rendering with de/rehydration', () => { it('should not mismatch on success', async () => { const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) const fetchDataSuccess = vi.fn(fetchData) @@ -128,7 +128,7 @@ describe('Server side rendering with de/rehydration', () => { it('should not mismatch on error', async () => { const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) const fetchDataError = vi.fn(() => { throw new Error('fetchDataError') @@ -209,7 +209,7 @@ describe('Server side rendering with de/rehydration', () => { it('should not mismatch on queries that were not prefetched', async () => { const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) const fetchDataSuccess = vi.fn(fetchData) diff --git a/packages/preact-query/src/__tests__/useMutation.test.tsx b/packages/preact-query/src/__tests__/useMutation.test.tsx index a5c3f4b73a..8fb438b879 100644 --- a/packages/preact-query/src/__tests__/useMutation.test.tsx +++ b/packages/preact-query/src/__tests__/useMutation.test.tsx @@ -1293,7 +1293,7 @@ describe('useMutation', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { const { mutate } = useMutation({ mutationFn: () => { @@ -1334,7 +1334,7 @@ describe('useMutation', () => { it('should be able to throw an error when throwOnError is a function that returns true', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) let boundary = false function Page() { const { mutate, error } = useMutation({ diff --git a/packages/preact-query/src/__tests__/usePrefetchInfiniteQuery.test.tsx b/packages/preact-query/src/__tests__/usePrefetchInfiniteQuery.test.tsx index 2d10cd106f..f97528e9eb 100644 --- a/packages/preact-query/src/__tests__/usePrefetchInfiniteQuery.test.tsx +++ b/packages/preact-query/src/__tests__/usePrefetchInfiniteQuery.test.tsx @@ -29,7 +29,7 @@ describe('usePrefetchInfiniteQuery', () => { vi.useRealTimers() }) - const Fallback = vi.fn().mockImplementation(() =>
Loading...
) + const Fallback = vi.fn().mockReturnValue(
Loading...
) it('should prefetch an infinite query if query state does not exist', async () => { const data = [ diff --git a/packages/preact-query/src/__tests__/usePrefetchQuery.test.tsx b/packages/preact-query/src/__tests__/usePrefetchQuery.test.tsx index 05bfdf3521..f3c28a4d06 100644 --- a/packages/preact-query/src/__tests__/usePrefetchQuery.test.tsx +++ b/packages/preact-query/src/__tests__/usePrefetchQuery.test.tsx @@ -101,7 +101,7 @@ describe('usePrefetchQuery', () => { it('should let errors fall through and not refetch failed queries', async () => { const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) const queryFn = vi.fn(() => sleep(10).then(() => 'Not an error')) const queryOpts = { @@ -109,6 +109,7 @@ describe('usePrefetchQuery', () => { queryFn, } + // oxlint-disable-next-line vitest/prefer-mock-return-shorthand -- the promise must be created when the mock is called, not when it is set up queryFn.mockImplementationOnce(() => sleep(10).then(() => { throw new Error('Oops! Server error!') @@ -181,7 +182,7 @@ describe('usePrefetchQuery', () => { it('should be able to recover from errors and try fetching again', async () => { const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) const queryFn = vi.fn(() => sleep(10).then(() => 'This is fine :dog: :fire:'), ) @@ -191,6 +192,7 @@ describe('usePrefetchQuery', () => { queryFn, } + // oxlint-disable-next-line vitest/prefer-mock-return-shorthand -- the promise must be created when the mock is called, not when it is set up queryFn.mockImplementationOnce(() => sleep(10).then(() => { throw new Error('Oops! Server error!') @@ -258,7 +260,7 @@ describe('usePrefetchQuery', () => { ), } - const Fallback = vi.fn().mockImplementation(() =>
Loading...
) + const Fallback = vi.fn().mockReturnValue(
Loading...
) function FirstQuery({ children }: { children?: VNode }) { const state = useSuspenseQuery(firstQueryOpts) diff --git a/packages/preact-query/src/__tests__/useQueries.test.tsx b/packages/preact-query/src/__tests__/useQueries.test.tsx index b3c5cb39a8..b0d3ce8e1a 100644 --- a/packages/preact-query/src/__tests__/useQueries.test.tsx +++ b/packages/preact-query/src/__tests__/useQueries.test.tsx @@ -142,7 +142,7 @@ describe('useQueries', () => { it("should throw error if in one of queries' queryFn throws and throwOnError is in use", async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key1 = queryKey() const key2 = queryKey() const key3 = queryKey() @@ -208,7 +208,7 @@ describe('useQueries', () => { it("should throw error if in one of queries' queryFn throws and throwOnError function resolves to true", async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key1 = queryKey() const key2 = queryKey() const key3 = queryKey() @@ -276,7 +276,7 @@ describe('useQueries', () => { it("should throw error if in one of queries' queryFn rejects with a falsy error and throwOnError is in use", async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { diff --git a/packages/preact-query/src/__tests__/useQuery.test.tsx b/packages/preact-query/src/__tests__/useQuery.test.tsx index 8eaff5c9f5..a10fd29030 100644 --- a/packages/preact-query/src/__tests__/useQuery.test.tsx +++ b/packages/preact-query/src/__tests__/useQuery.test.tsx @@ -2708,7 +2708,7 @@ describe('useQuery', () => { it('should set status to error if queryFn throws', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -2739,7 +2739,7 @@ describe('useQuery', () => { it('should throw error if queryFn throws and throwOnError is in use', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -2773,7 +2773,7 @@ describe('useQuery', () => { it('should throw error if queryFn rejects with a falsy error and throwOnError is in use', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -2865,7 +2865,7 @@ describe('useQuery', () => { it('should throw error instead of setting status when error should be thrown', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() @@ -3546,10 +3546,10 @@ describe('useQuery', () => { const states: Array> = [] const queryFn = vi.fn<(...args: Array) => string>() - queryFn.mockImplementation(() => 'data') + queryFn.mockReturnValue('data') const prefetchQueryFn = vi.fn<(...args: Array) => string>() - prefetchQueryFn.mockImplementation(() => 'not yet...') + prefetchQueryFn.mockReturnValue('not yet...') await queryClient .query({ @@ -3580,11 +3580,11 @@ describe('useQuery', () => { const key = queryKey() const queryFn = vi.fn<(...args: Array) => string>() - queryFn.mockImplementation(() => 'data') + queryFn.mockReturnValue('data') - const prefetchQueryFn = - vi.fn<(...args: Array) => Promise>() - prefetchQueryFn.mockImplementation(() => sleep(10).then(() => 'not yet...')) + const prefetchQueryFn = vi.fn<(...args: Array) => Promise>( + () => sleep(10).then(() => 'not yet...'), + ) void queryClient .query({ @@ -3896,7 +3896,7 @@ describe('useQuery', () => { it('should support enabled:false in query object syntax', () => { const key = queryKey() const queryFn = vi.fn<(...args: Array) => string>() - queryFn.mockImplementation(() => 'data') + queryFn.mockReturnValue('data') function Page() { const { fetchStatus } = useQuery({ @@ -4912,8 +4912,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(() => + const queryFn = vi.fn<(...args: Array) => unknown>(() => sleep(10).then(() => Promise.reject(new Error('Suspense Error Bingo'))), ) @@ -6431,7 +6430,7 @@ describe('useQuery', () => { // Mock console error to avoid noise when test is run const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() const queryFn = () => 'data' @@ -6494,7 +6493,7 @@ describe('useQuery', () => { it('should allow enabled: true and queryFn: skipToken', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function App() { @@ -6674,7 +6673,7 @@ describe('useQuery', () => { it('should retry failed initialPromise on the client', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() const serverQueryClient = new QueryClient({ @@ -6755,9 +6754,7 @@ describe('useQuery', () => { it('should not fetch for the duration of the restoring period when isRestoring is true', async () => { const key = queryKey() - const queryFn = vi - .fn() - .mockImplementation(() => sleep(10).then(() => 'data')) + const queryFn = vi.fn(() => sleep(10).then(() => 'data')) function Page() { const result = useQuery({ diff --git a/packages/preact-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx b/packages/preact-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx index 14b4cf4fe6..a91931a4b8 100644 --- a/packages/preact-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx +++ b/packages/preact-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx @@ -63,7 +63,7 @@ describe('useSuspenseInfiniteQuery', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -98,7 +98,7 @@ describe('useSuspenseInfiniteQuery', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { diff --git a/packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx b/packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx index 1333aca030..3f247158e5 100644 --- a/packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx +++ b/packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx @@ -522,7 +522,7 @@ describe('useSuspenseQueries', () => { it('should throw error when a queryFn rejects with a falsy error', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -561,7 +561,7 @@ describe('useSuspenseQueries', () => { it('should throw error when queryKey changes and new query fails', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page({ fail }: { fail: boolean }) { @@ -763,7 +763,7 @@ describe('useSuspenseQueries', () => { it('should show error boundary even with gcTime:0 (#7853)', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let count = 0 @@ -909,7 +909,7 @@ describe('useSuspenseQueries', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -945,7 +945,7 @@ describe('useSuspenseQueries', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { diff --git a/packages/preact-query/src/__tests__/useSuspenseQuery.test.tsx b/packages/preact-query/src/__tests__/useSuspenseQuery.test.tsx index 219ce836b1..41a4a1f865 100644 --- a/packages/preact-query/src/__tests__/useSuspenseQuery.test.tsx +++ b/packages/preact-query/src/__tests__/useSuspenseQuery.test.tsx @@ -231,7 +231,7 @@ describe('useSuspenseQuery', () => { it('should reset error state if new component instances are mounted', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let succeed = false @@ -298,7 +298,7 @@ describe('useSuspenseQuery', () => { it('should retry fetch if the reset error boundary has been reset', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let succeed = false @@ -449,7 +449,7 @@ describe('useSuspenseQuery', () => { it('should retry fetch if the reset error boundary has been reset with global hook', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let succeed = false @@ -518,7 +518,7 @@ describe('useSuspenseQuery', () => { it('should throw errors to the error boundary by default', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -559,7 +559,7 @@ describe('useSuspenseQuery', () => { it('should throw select errors to the error boundary by default', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -601,7 +601,7 @@ describe('useSuspenseQuery', () => { it('should error caught in error boundary without infinite loop', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page({ succeed }: { succeed: boolean }) { @@ -680,7 +680,7 @@ describe('useSuspenseQuery', () => { it('should error caught in error boundary without infinite loop when query keys changed', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) let succeed = true function Child({ keyVal }: { keyVal: number }) { @@ -804,7 +804,7 @@ describe('useSuspenseQuery', () => { it('should not throw background errors to the error boundary', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) let succeed = true const key = queryKey() @@ -989,7 +989,7 @@ describe('useSuspenseQuery', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -1022,7 +1022,7 @@ describe('useSuspenseQuery', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { diff --git a/packages/query-core/src/__tests__/focusManager.test.tsx b/packages/query-core/src/__tests__/focusManager.test.tsx index 5c7a64f742..7ccc3c9053 100644 --- a/packages/query-core/src/__tests__/focusManager.test.tsx +++ b/packages/query-core/src/__tests__/focusManager.test.tsx @@ -55,8 +55,8 @@ describe('focusManager', () => { it('should not call cleanup (removeEventListener) if window is not defined', () => { const windowSpy = vi.spyOn(globalThis, 'window', 'get') - windowSpy.mockImplementation( - () => undefined as unknown as Window & typeof globalThis, + windowSpy.mockReturnValue( + undefined as unknown as Window & typeof globalThis, ) const removeEventListenerSpy = vi.spyOn(globalThis, 'removeEventListener') @@ -93,8 +93,8 @@ describe('focusManager', () => { }) it('should replace default window listener when a new event listener is set', () => { - const unsubscribeSpy = vi.fn().mockImplementation(() => undefined) - const handlerSpy = vi.fn().mockImplementation(() => unsubscribeSpy) + const unsubscribeSpy = vi.fn().mockReturnValue(undefined) + const handlerSpy = vi.fn().mockReturnValue(unsubscribeSpy) focusManager.setEventListener(() => handlerSpy()) @@ -132,7 +132,7 @@ describe('focusManager', () => { }) it('should keep setup function even if last listener unsubscribes', () => { - const setupSpy = vi.fn().mockImplementation(() => () => undefined) + const setupSpy = vi.fn().mockReturnValue(() => undefined) focusManager.setEventListener(setupSpy) diff --git a/packages/query-core/src/__tests__/hydration.test.tsx b/packages/query-core/src/__tests__/hydration.test.tsx index deb2468399..7b00ae848f 100644 --- a/packages/query-core/src/__tests__/hydration.test.tsx +++ b/packages/query-core/src/__tests__/hydration.test.tsx @@ -402,7 +402,7 @@ describe('dehydration and rehydration', () => { const errorKey = queryKey() const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) const queryCache = new QueryCache() const queryClient = new QueryClient({ queryCache }) @@ -573,7 +573,7 @@ describe('dehydration and rehydration', () => { it('should be able to dehydrate mutations and continue on hydration', async () => { const key = queryKey() const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) const onlineMock = mockOnlineManagerIsOnline(false) const serverAddTodo = vi.fn().mockRejectedValue(new Error('offline')) @@ -658,7 +658,7 @@ describe('dehydration and rehydration', () => { it('should not dehydrate mutations if dehydrateMutations is set to false', async () => { const key = queryKey() const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) const serverAddTodo = vi.fn().mockRejectedValue(new Error('offline')) @@ -690,7 +690,7 @@ describe('dehydration and rehydration', () => { it('should not dehydrate mutation if mutation state is set to pause', async () => { const key = queryKey() const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) const serverAddTodo = vi.fn().mockRejectedValue(new Error('offline')) @@ -1382,7 +1382,7 @@ describe('dehydration and rehydration', () => { it('should redact errors by default when shouldRedactErrors is not set', async () => { const key = queryKey() const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) const queryCache = new QueryCache() const queryClient = new QueryClient({ @@ -1417,7 +1417,7 @@ describe('dehydration and rehydration', () => { process.env.NODE_ENV = 'development' const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) const queryCache = new QueryCache() const queryClient = new QueryClient({ diff --git a/packages/query-core/src/__tests__/notifyManager.test.tsx b/packages/query-core/src/__tests__/notifyManager.test.tsx index 2182490d9e..4a7cb7b2dd 100644 --- a/packages/query-core/src/__tests__/notifyManager.test.tsx +++ b/packages/query-core/src/__tests__/notifyManager.test.tsx @@ -21,7 +21,7 @@ describe('notifyManager', () => { it('should use default batchNotifyFn', async () => { const notifyManagerTest = createNotifyManager() - const callbackScheduleSpy = vi.fn().mockImplementation(() => sleep(20)) + const callbackScheduleSpy = vi.fn(() => sleep(20)) const callbackBatchLevel2Spy = vi.fn().mockImplementation(() => { notifyManagerTest.schedule(callbackScheduleSpy) }) diff --git a/packages/query-core/src/__tests__/onlineManager.test.tsx b/packages/query-core/src/__tests__/onlineManager.test.tsx index c90aea4d5b..7f20165695 100644 --- a/packages/query-core/src/__tests__/onlineManager.test.tsx +++ b/packages/query-core/src/__tests__/onlineManager.test.tsx @@ -18,7 +18,7 @@ describe('onlineManager', () => { // Force navigator to be undefined // @ts-expect-error - navigatorSpy.mockImplementation(() => undefined) + navigatorSpy.mockReturnValue(undefined) expect(onlineManager.isOnline()).toBe(true) @@ -27,7 +27,7 @@ describe('onlineManager', () => { it('should return true from isOnline if navigator.onLine is true', () => { const navigatorSpy = vi.spyOn(navigator, 'onLine', 'get') - navigatorSpy.mockImplementation(() => true) + navigatorSpy.mockReturnValue(true) expect(onlineManager.isOnline()).toBe(true) @@ -65,8 +65,8 @@ describe('onlineManager', () => { it('should not call cleanup (removeEventListener) if window is not defined', () => { const windowSpy = vi.spyOn(globalThis, 'window', 'get') - windowSpy.mockImplementation( - () => undefined as unknown as Window & typeof globalThis, + windowSpy.mockReturnValue( + undefined as unknown as Window & typeof globalThis, ) const removeEventListenerSpy = vi.spyOn(globalThis, 'removeEventListener') @@ -140,7 +140,7 @@ describe('onlineManager', () => { }) it('should keep setup function even if last listener unsubscribes', () => { - const setupSpy = vi.fn().mockImplementation(() => () => undefined) + const setupSpy = vi.fn().mockReturnValue(() => undefined) onlineManager.setEventListener(setupSpy) diff --git a/packages/query-core/src/__tests__/query.test.tsx b/packages/query-core/src/__tests__/query.test.tsx index baf81382b1..e098fb38fd 100644 --- a/packages/query-core/src/__tests__/query.test.tsx +++ b/packages/query-core/src/__tests__/query.test.tsx @@ -491,9 +491,9 @@ describe('query', () => { it('should be able to refetch a cancelled query', async () => { const key = queryKey() - const queryFn = vi.fn<(...args: Array) => unknown>() - - queryFn.mockImplementation(() => sleep(50).then(() => 'data')) + const queryFn = vi.fn<(...args: Array) => unknown>(() => + sleep(50).then(() => 'data'), + ) void queryClient.query({ queryKey: key, queryFn }).catch(noop) const query = queryCache.find({ queryKey: key })! @@ -939,7 +939,7 @@ describe('query', () => { it('should dispatch an error from fetch if the queryFn returns undefined', async () => { const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) const key = queryKey() const observer = new QueryObserver(queryClient, { @@ -1155,11 +1155,11 @@ describe('query', () => { it('should have an error log when queryFn data is not serializable', async () => { const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) const key = queryKey() - const queryFn = vi.fn() + const queryFn = vi.fn(() => sleep(10).then(() => data)) const initialData = { foo: 'bar', @@ -1171,8 +1171,6 @@ describe('query', () => { }, } - queryFn.mockImplementation(() => sleep(10).then(() => data)) - void queryClient .query({ queryKey: key, @@ -1203,9 +1201,9 @@ describe('query', () => { it('should have an error status when setData has any error inside', async () => { const key = queryKey() - const queryFn = vi - .fn<() => Promise>() - .mockImplementation(() => sleep(10).then(() => 'data')) + const queryFn = vi.fn<() => Promise>(() => + sleep(10).then(() => 'data'), + ) void queryClient .query({ @@ -1402,7 +1400,7 @@ describe('query', () => { it('should not increment dataUpdateCount when setting initialData on prefetched query', async () => { const key = queryKey() - const queryFn = vi.fn().mockImplementation(() => 'fetched-data') + const queryFn = vi.fn().mockReturnValue('fetched-data') // First prefetch the query (creates query without data) void queryClient diff --git a/packages/query-core/src/__tests__/queryClient.test.tsx b/packages/query-core/src/__tests__/queryClient.test.tsx index ef4a84eef3..154b032a48 100644 --- a/packages/query-core/src/__tests__/queryClient.test.tsx +++ b/packages/query-core/src/__tests__/queryClient.test.tsx @@ -2770,7 +2770,7 @@ describe('queryClient', () => { it('should resume paused mutations when coming online', async () => { const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) onlineManager.setOnline(false) const observer1 = new MutationObserver(queryClient, { @@ -2828,7 +2828,7 @@ describe('queryClient', () => { it('should resume paused mutations one after the other when in the same scope when invoked manually at the same time', async () => { const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) onlineManager.setOnline(false) const orders: Array = [] @@ -2872,7 +2872,7 @@ describe('queryClient', () => { it('should resumePausedMutations when coming online after having called resumePausedMutations while offline', async () => { const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) onlineManager.setOnline(false) const observer = new MutationObserver(queryClient, { @@ -2894,7 +2894,7 @@ describe('queryClient', () => { it('should resumePausedMutations when coming online after having restored cache (and resumed) while offline', async () => { const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) onlineManager.setOnline(false) const observer = new MutationObserver(queryClient, { diff --git a/packages/query-core/src/__tests__/retryer.test.tsx b/packages/query-core/src/__tests__/retryer.test.tsx index 5652795a55..d856c529b5 100644 --- a/packages/query-core/src/__tests__/retryer.test.tsx +++ b/packages/query-core/src/__tests__/retryer.test.tsx @@ -100,7 +100,7 @@ describe('createRetryer', () => { it('should reject with a CancelledError carrying the cancel options and call onCancel', async () => { const onCancel = vi.fn() - const fn = vi.fn().mockImplementation(() => new Promise(() => {})) + const fn = vi.fn(() => new Promise(() => {})) const retryer = createRetryer({ fn, onCancel, diff --git a/packages/query-core/src/__tests__/utils.test.tsx b/packages/query-core/src/__tests__/utils.test.tsx index de645e7d1f..dcbc1e7701 100644 --- a/packages/query-core/src/__tests__/utils.test.tsx +++ b/packages/query-core/src/__tests__/utils.test.tsx @@ -649,7 +649,7 @@ describe('core/utils', () => { it('should return a function that rejects with missing queryFn error when queryFn is set to skipToken', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const resolved = ensureQueryFn({ queryFn: skipToken, diff --git a/packages/query-persist-client-core/src/__tests__/persist.test.ts b/packages/query-persist-client-core/src/__tests__/persist.test.ts index 74a1277185..a1f0b13229 100644 --- a/packages/query-persist-client-core/src/__tests__/persist.test.ts +++ b/packages/query-persist-client-core/src/__tests__/persist.test.ts @@ -107,11 +107,11 @@ describe('persist', () => { it('should rethrow exceptions in `restoreClient`', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const consoleWarnMock = vi .spyOn(console, 'warn') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const restoreError = new Error('Error restoring client') @@ -135,11 +135,11 @@ describe('persist', () => { it('should rethrow exceptions in `removeClient` before `restoreClient`', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const consoleWarnMock = vi .spyOn(console, 'warn') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const restoreError = new Error('Error restoring client') const removeError = new Error('Error removing client') diff --git a/packages/react-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx b/packages/react-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx index 3831840314..296a67f438 100644 --- a/packages/react-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx +++ b/packages/react-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx @@ -567,10 +567,8 @@ describe('PersistQueryClientProvider', () => { it('should remove cache after non-successful restoring', async () => { const key = queryKey() const consoleErrorMock = vi.spyOn(console, 'error') - const consoleWarnMock = vi - .spyOn(console, 'warn') - .mockImplementation(() => undefined) - consoleErrorMock.mockImplementation(() => undefined) + const consoleWarnMock = vi.spyOn(console, 'warn').mockReturnValue(undefined) + consoleErrorMock.mockReturnValue(undefined) const queryClient = new QueryClient() const removeClient = vi.fn() @@ -639,12 +637,8 @@ describe('PersistQueryClientProvider', () => { const onSuccess = vi.fn() - const queryFn1 = vi - .fn() - .mockImplementation(() => sleep(10).then(() => 'queryFn1')) - const queryFn2 = vi - .fn() - .mockImplementation(() => sleep(10).then(() => 'queryFn2')) + const queryFn1 = vi.fn(() => sleep(10).then(() => 'queryFn1')) + const queryFn2 = vi.fn(() => sleep(10).then(() => 'queryFn2')) function App() { const [client, setClient] = React.useState( diff --git a/packages/react-query/src/__tests__/QueryClientProvider.test.tsx b/packages/react-query/src/__tests__/QueryClientProvider.test.tsx index 3e4bb555f7..93eab5ec54 100644 --- a/packages/react-query/src/__tests__/QueryClientProvider.test.tsx +++ b/packages/react-query/src/__tests__/QueryClientProvider.test.tsx @@ -147,7 +147,7 @@ describe('QueryClientProvider', () => { it('should throw an error if no query client has been set', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { useQueryClient() diff --git a/packages/react-query/src/__tests__/QueryResetErrorBoundary.test.tsx b/packages/react-query/src/__tests__/QueryResetErrorBoundary.test.tsx index 9479cad27b..81be5dfca8 100644 --- a/packages/react-query/src/__tests__/QueryResetErrorBoundary.test.tsx +++ b/packages/react-query/src/__tests__/QueryResetErrorBoundary.test.tsx @@ -33,7 +33,7 @@ describe('QueryErrorResetBoundary', () => { it('should retry fetch if the reset error boundary has been reset', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let succeed = false @@ -94,7 +94,7 @@ describe('QueryErrorResetBoundary', () => { it('should not throw error if query is disabled', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let succeed = false @@ -161,7 +161,7 @@ describe('QueryErrorResetBoundary', () => { it('should not throw error if query is disabled, and refetch if query becomes enabled again', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() @@ -229,7 +229,7 @@ describe('QueryErrorResetBoundary', () => { it('should throw error if query is disabled and manually refetch', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() @@ -297,7 +297,7 @@ describe('QueryErrorResetBoundary', () => { it('should not retry fetch if the reset error boundary has not been reset', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() @@ -358,7 +358,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 () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() @@ -422,7 +422,7 @@ describe('QueryErrorResetBoundary', () => { it('should not retry fetch if the reset error boundary has not been reset after a previous reset', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() @@ -504,7 +504,7 @@ describe('QueryErrorResetBoundary', () => { it('should throw again on error after the reset error boundary has been reset', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let fetchCount = 0 @@ -570,7 +570,7 @@ describe('QueryErrorResetBoundary', () => { it('should never render the component while the query is in error state', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let fetchCount = 0 @@ -645,7 +645,7 @@ describe('QueryErrorResetBoundary', () => { it('should render children', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { return ( @@ -670,7 +670,7 @@ describe('QueryErrorResetBoundary', () => { it('should show error boundary when using tracked queries even though we do not track the error field', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() @@ -812,7 +812,7 @@ describe('QueryErrorResetBoundary', () => { it('should retry fetch if the reset error boundary has been reset', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let succeed = false @@ -879,7 +879,7 @@ describe('QueryErrorResetBoundary', () => { const key = queryKey() const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) let succeed = false diff --git a/packages/react-query/src/__tests__/ssr-hydration.test.tsx b/packages/react-query/src/__tests__/ssr-hydration.test.tsx index 8078df3034..872c0a097f 100644 --- a/packages/react-query/src/__tests__/ssr-hydration.test.tsx +++ b/packages/react-query/src/__tests__/ssr-hydration.test.tsx @@ -49,7 +49,7 @@ describe('Server side rendering with de/rehydration', () => { it('should not mismatch on success', async () => { const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) const fetchDataSuccess = vi.fn(fetchData) const key = queryKey() @@ -127,7 +127,7 @@ describe('Server side rendering with de/rehydration', () => { it('should not mismatch on error', async () => { const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) const fetchDataError = vi.fn(() => { throw new Error('fetchDataError') @@ -209,7 +209,7 @@ describe('Server side rendering with de/rehydration', () => { it('should not mismatch on queries that were not prefetched', async () => { const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) const fetchDataSuccess = vi.fn(fetchData) const key = queryKey() diff --git a/packages/react-query/src/__tests__/useMutation.test.tsx b/packages/react-query/src/__tests__/useMutation.test.tsx index 6a133e77b7..3f7eaf951f 100644 --- a/packages/react-query/src/__tests__/useMutation.test.tsx +++ b/packages/react-query/src/__tests__/useMutation.test.tsx @@ -1292,7 +1292,7 @@ describe('useMutation', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { const { mutate } = useMutation({ mutationFn: () => { @@ -1333,7 +1333,7 @@ describe('useMutation', () => { it('should be able to throw an error when throwOnError is a function that returns true', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) let boundary = false function Page() { const { mutate, error } = useMutation({ diff --git a/packages/react-query/src/__tests__/usePrefetchInfiniteQuery.test.tsx b/packages/react-query/src/__tests__/usePrefetchInfiniteQuery.test.tsx index ffa2c66f6a..0736a920a2 100644 --- a/packages/react-query/src/__tests__/usePrefetchInfiniteQuery.test.tsx +++ b/packages/react-query/src/__tests__/usePrefetchInfiniteQuery.test.tsx @@ -27,7 +27,7 @@ describe('usePrefetchInfiniteQuery', () => { }) it('should prefetch an infinite query if query state does not exist', async () => { - const Fallback = vi.fn().mockImplementation(() =>
Loading...
) + const Fallback = vi.fn().mockReturnValue(
Loading...
) const data = [ 'Do you fetch on render?', 'Or do you render as you fetch?', @@ -88,7 +88,7 @@ describe('usePrefetchInfiniteQuery', () => { }) it('should not display fallback if the query cache is already populated', async () => { - const Fallback = vi.fn().mockImplementation(() =>
Loading...
) + const Fallback = vi.fn().mockReturnValue(
Loading...
) const data = [ 'Prefetch rocks!', 'No waterfalls, boy!', diff --git a/packages/react-query/src/__tests__/usePrefetchQuery.test.tsx b/packages/react-query/src/__tests__/usePrefetchQuery.test.tsx index 3906f342f7..ea8d5c5fdc 100644 --- a/packages/react-query/src/__tests__/usePrefetchQuery.test.tsx +++ b/packages/react-query/src/__tests__/usePrefetchQuery.test.tsx @@ -99,7 +99,7 @@ describe('usePrefetchQuery', () => { it('should let errors fall through and not refetch failed queries', async () => { const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) const queryFn = vi.fn(() => sleep(10).then(() => 'Not an error')) const queryOpts = { @@ -107,6 +107,7 @@ describe('usePrefetchQuery', () => { queryFn, } + // oxlint-disable-next-line vitest/prefer-mock-return-shorthand -- the promise must be created when the mock is called, not when it is set up queryFn.mockImplementationOnce(() => sleep(10).then(() => { throw new Error('Oops! Server error!') @@ -179,7 +180,7 @@ describe('usePrefetchQuery', () => { it('should be able to recover from errors and try fetching again', async () => { const consoleErrorMock = vi.spyOn(console, 'error') - consoleErrorMock.mockImplementation(() => undefined) + consoleErrorMock.mockReturnValue(undefined) const queryFn = vi.fn(() => sleep(10).then(() => 'This is fine :dog: :fire:'), ) @@ -189,6 +190,7 @@ describe('usePrefetchQuery', () => { queryFn, } + // oxlint-disable-next-line vitest/prefer-mock-return-shorthand -- the promise must be created when the mock is called, not when it is set up queryFn.mockImplementationOnce(() => sleep(10).then(() => { throw new Error('Oops! Server error!') @@ -256,7 +258,7 @@ describe('usePrefetchQuery', () => { ), } - const Fallback = vi.fn().mockImplementation(() =>
Loading...
) + const Fallback = vi.fn().mockReturnValue(
Loading...
) function FirstQuery({ children }: { children?: React.ReactNode }) { const state = useSuspenseQuery(firstQueryOpts) diff --git a/packages/react-query/src/__tests__/useQueries.test.tsx b/packages/react-query/src/__tests__/useQueries.test.tsx index de9dc23f6d..b647a9174c 100644 --- a/packages/react-query/src/__tests__/useQueries.test.tsx +++ b/packages/react-query/src/__tests__/useQueries.test.tsx @@ -141,7 +141,7 @@ describe('useQueries', () => { it("should throw error if in one of queries' queryFn throws and throwOnError is in use", async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key1 = queryKey() const key2 = queryKey() const key3 = queryKey() @@ -207,7 +207,7 @@ describe('useQueries', () => { it("should throw error if in one of queries' queryFn throws and throwOnError function resolves to true", async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key1 = queryKey() const key2 = queryKey() const key3 = queryKey() @@ -275,7 +275,7 @@ describe('useQueries', () => { it("should throw error if in one of queries' queryFn rejects with a falsy error and throwOnError is in use", async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { diff --git a/packages/react-query/src/__tests__/useQuery.test.tsx b/packages/react-query/src/__tests__/useQuery.test.tsx index bac8cc7de8..3a2815cfc3 100644 --- a/packages/react-query/src/__tests__/useQuery.test.tsx +++ b/packages/react-query/src/__tests__/useQuery.test.tsx @@ -2700,7 +2700,7 @@ describe('useQuery', () => { it('should set status to error if queryFn throws', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -2731,7 +2731,7 @@ describe('useQuery', () => { it('should throw error if queryFn throws and throwOnError is in use', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -2765,7 +2765,7 @@ describe('useQuery', () => { it('should throw error if queryFn rejects with a falsy error and throwOnError is in use', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -2853,7 +2853,7 @@ describe('useQuery', () => { it('should throw error instead of setting status when error should be thrown', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() @@ -3534,10 +3534,10 @@ describe('useQuery', () => { const states: Array> = [] const queryFn = vi.fn<(...args: Array) => string>() - queryFn.mockImplementation(() => 'data') + queryFn.mockReturnValue('data') const prefetchQueryFn = vi.fn<(...args: Array) => string>() - prefetchQueryFn.mockImplementation(() => 'not yet...') + prefetchQueryFn.mockReturnValue('not yet...') await queryClient .query({ @@ -3568,11 +3568,11 @@ describe('useQuery', () => { const key = queryKey() const queryFn = vi.fn<(...args: Array) => string>() - queryFn.mockImplementation(() => 'data') + queryFn.mockReturnValue('data') - const prefetchQueryFn = - vi.fn<(...args: Array) => Promise>() - prefetchQueryFn.mockImplementation(() => sleep(10).then(() => 'not yet...')) + const prefetchQueryFn = vi.fn<(...args: Array) => Promise>( + () => sleep(10).then(() => 'not yet...'), + ) void queryClient .query({ @@ -3885,7 +3885,7 @@ describe('useQuery', () => { it('should support enabled:false in query object syntax', () => { const key = queryKey() const queryFn = vi.fn<(...args: Array) => string>() - queryFn.mockImplementation(() => 'data') + queryFn.mockReturnValue('data') function Page() { const { fetchStatus } = useQuery({ @@ -4897,8 +4897,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(() => + const queryFn = vi.fn<(...args: Array) => unknown>(() => sleep(10).then(() => Promise.reject(new Error('Suspense Error Bingo'))), ) @@ -6430,7 +6429,7 @@ describe('useQuery', () => { // Mock console error to avoid noise when test is run const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() const queryFn = () => 'data' @@ -6493,7 +6492,7 @@ describe('useQuery', () => { it('should allow enabled: true and queryFn: skipToken', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function App() { @@ -6673,7 +6672,7 @@ describe('useQuery', () => { it('should retry failed initialPromise on the client', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() const serverQueryClient = new QueryClient({ @@ -7042,9 +7041,7 @@ describe('useQuery', () => { it('should not fetch for the duration of the restoring period when isRestoring is true', async () => { const key = queryKey() - const queryFn = vi - .fn() - .mockImplementation(() => sleep(10).then(() => 'data')) + const queryFn = vi.fn(() => sleep(10).then(() => 'data')) function Page() { const result = useQuery({ diff --git a/packages/react-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx b/packages/react-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx index 5c0cb8517a..5406a1f1b0 100644 --- a/packages/react-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx +++ b/packages/react-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx @@ -120,7 +120,7 @@ describe('useSuspenseInfiniteQuery', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -155,7 +155,7 @@ describe('useSuspenseInfiniteQuery', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { diff --git a/packages/react-query/src/__tests__/useSuspenseQueries.test.tsx b/packages/react-query/src/__tests__/useSuspenseQueries.test.tsx index 53e034dcc8..cba4857db2 100644 --- a/packages/react-query/src/__tests__/useSuspenseQueries.test.tsx +++ b/packages/react-query/src/__tests__/useSuspenseQueries.test.tsx @@ -277,7 +277,7 @@ describe('useSuspenseQueries', () => { it('should not call combine while reset queries are pending again', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let shouldError = false @@ -573,7 +573,7 @@ describe('useSuspenseQueries', () => { it('should throw error when a queryFn rejects with a falsy error', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -608,7 +608,7 @@ describe('useSuspenseQueries', () => { it('should throw error when queryKey changes and new query fails', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -798,7 +798,7 @@ describe('useSuspenseQueries', () => { it('should show error boundary even with gcTime:0 (#7853)', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let count = 0 @@ -944,7 +944,7 @@ describe('useSuspenseQueries', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -980,7 +980,7 @@ describe('useSuspenseQueries', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { diff --git a/packages/react-query/src/__tests__/useSuspenseQuery.test.tsx b/packages/react-query/src/__tests__/useSuspenseQuery.test.tsx index db5da5e99d..ed034ae781 100644 --- a/packages/react-query/src/__tests__/useSuspenseQuery.test.tsx +++ b/packages/react-query/src/__tests__/useSuspenseQuery.test.tsx @@ -213,7 +213,7 @@ describe('useSuspenseQuery', () => { it('should reset error state if new component instances are mounted', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let succeed = false @@ -280,7 +280,7 @@ describe('useSuspenseQuery', () => { it('should retry fetch if the reset error boundary has been reset', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let succeed = false @@ -429,7 +429,7 @@ describe('useSuspenseQuery', () => { it('should retry fetch if the reset error boundary has been reset with global hook', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let succeed = false @@ -498,7 +498,7 @@ describe('useSuspenseQuery', () => { it('should throw errors to the error boundary by default', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -539,7 +539,7 @@ describe('useSuspenseQuery', () => { it('should throw select errors to the error boundary by default', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -581,7 +581,7 @@ describe('useSuspenseQuery', () => { it('should error caught in error boundary without infinite loop', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() let succeed = true @@ -649,7 +649,7 @@ describe('useSuspenseQuery', () => { it('should error caught in error boundary without infinite loop when query keys changed', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) let succeed = true function Page() { @@ -763,7 +763,7 @@ describe('useSuspenseQuery', () => { it('should not throw background errors to the error boundary', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) let succeed = true const key = queryKey() @@ -940,7 +940,7 @@ describe('useSuspenseQuery', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { @@ -973,7 +973,7 @@ describe('useSuspenseQuery', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const key = queryKey() function Page() { diff --git a/packages/solid-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx b/packages/solid-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx index 93821f191d..046d694f64 100644 --- a/packages/solid-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx +++ b/packages/solid-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx @@ -450,7 +450,7 @@ describe('PersistQueryClientProvider', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const queryClient = new QueryClient() const removeClient = vi.fn() const onSuccess = vi.fn() @@ -521,12 +521,8 @@ describe('PersistQueryClientProvider', () => { const onSuccess = vi.fn() - const queryFn1 = vi - .fn() - .mockImplementation(() => sleep(10).then(() => 'queryFn1')) - const queryFn2 = vi - .fn() - .mockImplementation(() => sleep(10).then(() => 'queryFn2')) + const queryFn1 = vi.fn(() => sleep(10).then(() => 'queryFn1')) + const queryFn2 = vi.fn(() => sleep(10).then(() => 'queryFn2')) function App() { const [client, setClient] = createSignal( diff --git a/packages/solid-query/src/__tests__/QueryClientProvider.test.tsx b/packages/solid-query/src/__tests__/QueryClientProvider.test.tsx index 56a68f0a4d..be91b6f47b 100644 --- a/packages/solid-query/src/__tests__/QueryClientProvider.test.tsx +++ b/packages/solid-query/src/__tests__/QueryClientProvider.test.tsx @@ -144,7 +144,7 @@ describe('QueryClientProvider', () => { it('should throw an error if no query client has been set', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { useQueryClient() @@ -162,7 +162,7 @@ describe('QueryClientProvider', () => { it('should not throw an error if user provides custom query client', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { const client = new QueryClient() @@ -203,7 +203,7 @@ describe('QueryClientProvider', () => { it('should defer missing provider errors until a resolver is called', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) let resolveClient!: () => QueryClient function Page() { diff --git a/packages/solid-query/src/__tests__/suspense.test.tsx b/packages/solid-query/src/__tests__/suspense.test.tsx index 8328bd5494..0e2db804b9 100644 --- a/packages/solid-query/src/__tests__/suspense.test.tsx +++ b/packages/solid-query/src/__tests__/suspense.test.tsx @@ -441,7 +441,7 @@ describe("useQuery's in Suspense mode", () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { const state = useQuery(() => ({ @@ -533,7 +533,7 @@ describe("useQuery's in Suspense mode", () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { const state = useQuery(() => ({ @@ -665,7 +665,7 @@ describe("useQuery's in Suspense mode", () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) let succeed = true @@ -729,7 +729,7 @@ describe("useQuery's in Suspense mode", () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { const [key, setKey] = createSignal(0) @@ -789,7 +789,7 @@ describe("useQuery's in Suspense mode", () => { it('should error caught in error boundary without infinite loop when enabled changed', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { const queryKeys = '1' diff --git a/packages/solid-query/src/__tests__/useMutation.test.tsx b/packages/solid-query/src/__tests__/useMutation.test.tsx index 93155fe2f1..350b872a4c 100644 --- a/packages/solid-query/src/__tests__/useMutation.test.tsx +++ b/packages/solid-query/src/__tests__/useMutation.test.tsx @@ -62,7 +62,7 @@ describe('useMutation', () => { it('should be able to reset `error`', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { const mutation = useMutation(() => ({ @@ -1040,7 +1040,7 @@ describe('useMutation', () => { it('should be able to throw an error when throwOnError is set to true', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { const mutation = useMutation(() => ({ @@ -1081,7 +1081,7 @@ describe('useMutation', () => { it('should be able to throw an error when throwOnError is a function that returns true', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) let boundary = false function Page() { diff --git a/packages/solid-query/src/__tests__/useQuery.test.tsx b/packages/solid-query/src/__tests__/useQuery.test.tsx index 626734f6d5..f74f410f2b 100644 --- a/packages/solid-query/src/__tests__/useQuery.test.tsx +++ b/packages/solid-query/src/__tests__/useQuery.test.tsx @@ -2040,7 +2040,7 @@ describe('useQuery', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { const state = useQuery(() => ({ @@ -2072,7 +2072,7 @@ describe('useQuery', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { const state = useQuery(() => ({ @@ -2109,7 +2109,7 @@ describe('useQuery', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { const state = useQuery(() => ({ @@ -2144,7 +2144,7 @@ describe('useQuery', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { const state = useQuery(() => ({ @@ -2181,7 +2181,7 @@ describe('useQuery', () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) function Page() { const state = useQuery(() => ({ @@ -2703,8 +2703,7 @@ describe('useQuery', () => { it('should retry specified number of times', async () => { const key = queryKey() - const queryFn = vi.fn<(...args: Array) => unknown>() - queryFn.mockImplementation(() => + const queryFn = vi.fn<(...args: Array) => unknown>(() => sleep(10).then(() => Promise.reject(new Error('Error test Barrett'))), ) @@ -2745,14 +2744,13 @@ describe('useQuery', () => { it('should not retry if retry function `false`', async () => { const key = queryKey() - const queryFn = vi.fn<(...args: Array) => unknown>() - - queryFn.mockImplementationOnce(() => - sleep(10).then(() => Promise.reject(new Error('Error test Tanner'))), + const queryFn = vi.fn<(...args: Array) => unknown>(() => + sleep(10).then(() => Promise.reject(new Error('NoRetry'))), ) - queryFn.mockImplementation(() => - sleep(10).then(() => Promise.reject(new Error('NoRetry'))), + // oxlint-disable-next-line vitest/prefer-mock-return-shorthand -- the promise must be created when the mock is called, not when it is set up + queryFn.mockImplementationOnce(() => + sleep(10).then(() => Promise.reject(new Error('Error test Tanner'))), ) function Page() { @@ -3012,10 +3010,10 @@ describe('useQuery', () => { const states: Array> = [] const queryFn = vi.fn<(...args: Array) => string>() - queryFn.mockImplementation(() => 'data') + queryFn.mockReturnValue('data') const prefetchQueryFn = vi.fn<(...args: Array) => string>() - prefetchQueryFn.mockImplementation(() => 'not yet...') + prefetchQueryFn.mockReturnValue('not yet...') void queryClient .query({ @@ -3046,12 +3044,13 @@ describe('useQuery', () => { it('should not refetch if not stale after a prefetch', async () => { const key = queryKey() - const queryFn = vi.fn<(...args: Array) => Promise>() - queryFn.mockImplementation(() => sleep(10).then(() => 'data')) + const queryFn = vi.fn<(...args: Array) => Promise>(() => + sleep(10).then(() => 'data'), + ) - const prefetchQueryFn = - vi.fn<(...args: Array) => Promise>() - prefetchQueryFn.mockImplementation(() => sleep(10).then(() => 'not yet...')) + const prefetchQueryFn = vi.fn<(...args: Array) => Promise>( + () => sleep(10).then(() => 'not yet...'), + ) void queryClient .query({ @@ -3430,7 +3429,7 @@ describe('useQuery', () => { it('should support enabled:false in query object syntax', () => { const key = queryKey() const queryFn = vi.fn<(...args: Array) => string>() - queryFn.mockImplementation(() => 'data') + queryFn.mockReturnValue('data') function Page() { const { fetchStatus } = useQuery(() => ({ @@ -4457,8 +4456,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(() => + const queryFn = vi.fn<(...args: Array) => unknown>(() => sleep(10).then(() => Promise.reject(new Error('Suspense Error Bingo'))), ) @@ -5616,9 +5614,7 @@ describe('useQuery', () => { it('should not fetch while restoring and refetch after restoring is complete', async () => { const key = queryKey() - const queryFn = vi - .fn() - .mockImplementation(() => sleep(10).then(() => 'data')) + const queryFn = vi.fn(() => sleep(10).then(() => 'data')) const [isRestoring, setIsRestoring] = createSignal(true) @@ -5686,9 +5682,7 @@ describe('useQuery', () => { const queryClient1 = new QueryClient() const queryClient2 = new QueryClient() - const queryFn = vi - .fn() - .mockImplementation(() => sleep(10).then(() => 'data')) + const queryFn = vi.fn(() => sleep(10).then(() => 'data')) function Page(props: { client: () => QueryClient }) { const query = useQuery( diff --git a/packages/svelte-query-persist-client/tests/PersistQueryClientProvider.svelte.test.ts b/packages/svelte-query-persist-client/tests/PersistQueryClientProvider.svelte.test.ts index 5588a91782..5805ac50c8 100644 --- a/packages/svelte-query-persist-client/tests/PersistQueryClientProvider.svelte.test.ts +++ b/packages/svelte-query-persist-client/tests/PersistQueryClientProvider.svelte.test.ts @@ -360,10 +360,8 @@ describe('PersistQueryClientProvider', () => { it('should remove cache after non-successful restoring', async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) - const consoleWarnMock = vi - .spyOn(console, 'warn') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) + const consoleWarnMock = vi.spyOn(console, 'warn').mockReturnValue(undefined) const queryClient = new QueryClient() const removeClient = vi.fn() diff --git a/packages/svelte-query/tests/createMutation/createMutation.svelte.test.ts b/packages/svelte-query/tests/createMutation/createMutation.svelte.test.ts index 17731d7f1e..3d0b4151a8 100644 --- a/packages/svelte-query/tests/createMutation/createMutation.svelte.test.ts +++ b/packages/svelte-query/tests/createMutation/createMutation.svelte.test.ts @@ -299,6 +299,7 @@ describe('createMutation', () => { const mutationFn = vi.fn<(value: Value) => Promise>() + // oxlint-disable-next-line vitest/prefer-mock-return-shorthand -- the promise must be created when the mock is called, not when it is set up mutationFn.mockImplementationOnce(() => sleep(20).then(() => Promise.reject(`Expected mock error`)), ) diff --git a/packages/svelte-query/tests/createQuery/createQuery.svelte.test.ts b/packages/svelte-query/tests/createQuery/createQuery.svelte.test.ts index 55e5f23ddc..7e2f8a1db7 100644 --- a/packages/svelte-query/tests/createQuery/createQuery.svelte.test.ts +++ b/packages/svelte-query/tests/createQuery/createQuery.svelte.test.ts @@ -1544,7 +1544,7 @@ describe('createQuery', () => { const key = queryKey() const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const rendered = render(Base, { props: { diff --git a/packages/svelte-query/tests/useMutationState/useMutationState.svelte.test.ts b/packages/svelte-query/tests/useMutationState/useMutationState.svelte.test.ts index 20a1e8a149..dde487d612 100644 --- a/packages/svelte-query/tests/useMutationState/useMutationState.svelte.test.ts +++ b/packages/svelte-query/tests/useMutationState/useMutationState.svelte.test.ts @@ -23,11 +23,9 @@ describe('useMutationState', () => { const successKey = queryKey() const errorKey = queryKey() const successMutationFn = vi.fn(() => sleep(10).then(() => 'data')) - const errorMutationFn = vi - .fn() - .mockImplementation(() => - sleep(20).then(() => Promise.reject(new Error('error'))), - ) + const errorMutationFn = vi.fn(() => + sleep(20).then(() => Promise.reject(new Error('error'))), + ) const rendered = render(Base, { props: { @@ -58,11 +56,9 @@ describe('useMutationState', () => { const successKey = queryKey() const errorKey = queryKey() const successMutationFn = vi.fn(() => sleep(10).then(() => 'data')) - const errorMutationFn = vi - .fn() - .mockImplementation(() => - sleep(20).then(() => Promise.reject(new Error('error'))), - ) + const errorMutationFn = vi.fn(() => + sleep(20).then(() => Promise.reject(new Error('error'))), + ) const rendered = render(Base, { props: { @@ -122,11 +118,9 @@ describe('useMutationState', () => { const successKey = queryKey() const errorKey = queryKey() const successMutationFn = vi.fn(() => sleep(10).then(() => 'data')) - const errorMutationFn = vi - .fn() - .mockImplementation(() => - sleep(20).then(() => Promise.reject(new Error('error'))), - ) + const errorMutationFn = vi.fn(() => + sleep(20).then(() => Promise.reject(new Error('error'))), + ) const rendered = render(Base, { props: { diff --git a/packages/vue-query/src/__tests__/useMutation.test.ts b/packages/vue-query/src/__tests__/useMutation.test.ts index c4a11543fa..9eb43e1486 100644 --- a/packages/vue-query/src/__tests__/useMutation.test.ts +++ b/packages/vue-query/src/__tests__/useMutation.test.ts @@ -575,7 +575,7 @@ describe('useMutation', () => { async () => { const consoleErrorMock = vi .spyOn(console, 'error') - .mockImplementation(() => undefined) + .mockReturnValue(undefined) const throwOnError = vi.fn().mockReturnValue(true) const { mutate } = useMutation({ mutationFn: () => diff --git a/packages/vue-query/src/__tests__/useQuery.test.ts b/packages/vue-query/src/__tests__/useQuery.test.ts index a0faa77216..b7a8a5d597 100644 --- a/packages/vue-query/src/__tests__/useQuery.test.ts +++ b/packages/vue-query/src/__tests__/useQuery.test.ts @@ -258,9 +258,7 @@ describe('useQuery', () => { const enabled = computed(() => !!data.value) - const dependentQueryFn = vi - .fn() - .mockImplementation(() => sleep(10).then(() => 'Some data')) + const dependentQueryFn = vi.fn(() => sleep(10).then(() => 'Some data')) const { fetchStatus, status } = useQuery( reactive({ queryKey: key2,