From eb7184d89d062633dc85fe163ecdfa3f6511235b Mon Sep 17 00:00:00 2001 From: fe-dudu Date: Thu, 3 Apr 2025 20:53:03 +0900 Subject: [PATCH] test(react-query): ensure HydrationBoundary does not hydrate when state is truthy and non-object --- .../src/__tests__/HydrationBoundary.test.tsx | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/packages/react-query/src/__tests__/HydrationBoundary.test.tsx b/packages/react-query/src/__tests__/HydrationBoundary.test.tsx index f81c028948..c014d87731 100644 --- a/packages/react-query/src/__tests__/HydrationBoundary.test.tsx +++ b/packages/react-query/src/__tests__/HydrationBoundary.test.tsx @@ -331,12 +331,8 @@ describe('React hydration', () => { , ) - await Promise.all( - Array.from({ length: 1000 }).map(async (_, index) => { - await vi.advanceTimersByTimeAsync(index) - expect(hydrateSpy).toHaveBeenCalledTimes(0) - }), - ) + await vi.runAllTimersAsync() + expect(hydrateSpy).toHaveBeenCalledTimes(0) hydrateSpy.mockRestore() queryClient.clear() @@ -365,4 +361,27 @@ describe('React hydration', () => { hydrateSpy.mockRestore() queryClient.clear() }) -}) + + test('should not hydrate queries if state is truthy and non-object', async () => { + const queryClient = createQueryClient() + const hydrateSpy = vi.spyOn(coreModule, 'hydrate') + + function Page() { + return null + } + + render( + + + + + , + ) + + await vi.runAllTimersAsync() + expect(hydrateSpy).toHaveBeenCalledTimes(0) + + hydrateSpy.mockRestore() + queryClient.clear() + }) +}) \ No newline at end of file