From 75662a3064f4bf13f3885ea2b2869cbe6fbee070 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Fri, 13 May 2022 17:10:37 -0400 Subject: [PATCH] Make useQuery stale variables test less flaky. --- src/react/hooks/__tests__/useQuery.test.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/react/hooks/__tests__/useQuery.test.tsx b/src/react/hooks/__tests__/useQuery.test.tsx index 6fa85c7834a..5f5b9b5a37f 100644 --- a/src/react/hooks/__tests__/useQuery.test.tsx +++ b/src/react/hooks/__tests__/useQuery.test.tsx @@ -437,11 +437,16 @@ describe('useQuery Hook', () => { expect(result.current[0].loading).toBe(true); expect(result.current[0].data).toBe(undefined); expect(result.current[0].variables).toEqual({ name: "world 2" }); + await waitForNextUpdate(); - expect(result.current[0].loading).toBe(false); - expect(result.current[0].data).toEqual({ hello: "world 2" }); - expect(result.current[0].variables).toEqual({ name: "world 2" }); + // TODO(investigate) Without waitFor, loading is sometimes still true + // here, after awaiting waitForNextUpdate(). + return waitFor(() => { + expect(result.current[0].loading).toBe(false); + expect(result.current[0].data).toEqual({ hello: "world 2" }); + expect(result.current[0].variables).toEqual({ name: "world 2" }); + }); }); // TODO: Rewrite this test