Skip to content

Commit

Permalink
Make useQuery stale variables test less flaky.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed May 13, 2022
1 parent 74d2072 commit 75662a3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/react/hooks/__tests__/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 75662a3

Please sign in to comment.