From 9f6bb17afa6f5ad3478935e7f05f55011cbf11f2 Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Mon, 15 Jun 2026 04:30:25 +0900 Subject: [PATCH] test(solid-query/useQueries): add test for not fetching during the restoring period when 'isRestoring' is true --- .../src/__tests__/useQueries.test.tsx | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/packages/solid-query/src/__tests__/useQueries.test.tsx b/packages/solid-query/src/__tests__/useQueries.test.tsx index 8392467a0b..4298d9e3da 100644 --- a/packages/solid-query/src/__tests__/useQueries.test.tsx +++ b/packages/solid-query/src/__tests__/useQueries.test.tsx @@ -11,7 +11,13 @@ import { fireEvent } from '@solidjs/testing-library' import * as QueryCore from '@tanstack/query-core' import { createRenderEffect, createSignal } from 'solid-js' import { queryKey, sleep } from '@tanstack/query-test-utils' -import { QueriesObserver, QueryCache, QueryClient, useQueries } from '..' +import { + IsRestoringProvider, + QueriesObserver, + QueryCache, + QueryClient, + useQueries, +} from '..' import { renderWithClient } from './utils' import type { QueryFunction, @@ -717,4 +723,59 @@ describe('useQueries', () => { await vi.advanceTimersByTimeAsync(20) QueriesObserverSpy.mockRestore() }) + + 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(() => sleep(10).then(() => 'data1')) + const queryFn2 = vi.fn(() => sleep(10).then(() => 'data2')) + + function Page() { + const results = useQueries(() => ({ + queries: [ + { queryKey: key1, queryFn: queryFn1 }, + { queryKey: key2, queryFn: queryFn2 }, + ], + })) + + return ( +
+
{results[0].status}
+
{results[1].status}
+
{results[0].fetchStatus}
+
{results[1].fetchStatus}
+
{results[0].data ?? 'undefined'}
+
{results[1].data ?? 'undefined'}
+
+ ) + } + + const rendered = renderWithClient(queryClient, () => ( + true}> + + + )) + + await vi.advanceTimersByTimeAsync(0) + + expect(rendered.getByTestId('status1')).toHaveTextContent('pending') + expect(rendered.getByTestId('status2')).toHaveTextContent('pending') + expect(rendered.getByTestId('fetchStatus1')).toHaveTextContent('idle') + expect(rendered.getByTestId('fetchStatus2')).toHaveTextContent('idle') + expect(rendered.getByTestId('data1')).toHaveTextContent('undefined') + expect(rendered.getByTestId('data2')).toHaveTextContent('undefined') + expect(queryFn1).toHaveBeenCalledTimes(0) + expect(queryFn2).toHaveBeenCalledTimes(0) + + await vi.advanceTimersByTimeAsync(10) + + expect(rendered.getByTestId('status1')).toHaveTextContent('pending') + expect(rendered.getByTestId('status2')).toHaveTextContent('pending') + expect(rendered.getByTestId('fetchStatus1')).toHaveTextContent('idle') + expect(rendered.getByTestId('fetchStatus2')).toHaveTextContent('idle') + expect(rendered.getByTestId('data1')).toHaveTextContent('undefined') + expect(rendered.getByTestId('data2')).toHaveTextContent('undefined') + expect(queryFn1).toHaveBeenCalledTimes(0) + expect(queryFn2).toHaveBeenCalledTimes(0) + }) })