Skip to content

Commit

Permalink
Rewrite test with toEqualQueryResult
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jan 16, 2025
1 parent 8b1cba1 commit 475e5b0
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions src/react/hooks/__tests__/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11060,14 +11060,28 @@ describe("useQuery Hook", () => {
}
);

expect(result.current.loading).toBe(true);
expect(result.current.data).toBeUndefined();
expect(result.current).toEqualQueryResult({
data: undefined,
called: true,
loading: true,
networkStatus: NetworkStatus.loading,
previousData: undefined,
variables: {},
});

await waitFor(() => {
expect(result.current.loading).toBe(false);
});

expect(result.current.data).toEqual({ hello: "hello 1" });
expect(result.current).toEqualQueryResult({
data: { hello: "hello 1" },
called: true,
loading: false,
networkStatus: NetworkStatus.ready,
previousData: undefined,
variables: {},
});

expect(cache.readQuery({ query })).toEqual({ hello: "hello 1" });

act(() => {
Expand All @@ -11078,14 +11092,28 @@ describe("useQuery Hook", () => {
setShow(true);
});

expect(result.current.loading).toBe(true);
expect(result.current.data).toBeUndefined();
expect(result.current).toEqualQueryResult({
data: undefined,
called: true,
loading: true,
networkStatus: NetworkStatus.loading,
previousData: undefined,
variables: {},
});

await waitFor(() => {
expect(result.current.loading).toBe(false);
});

expect(result.current.data).toEqual({ hello: "hello 2" });
expect(result.current).toEqualQueryResult({
data: { hello: "hello 2" },
called: true,
loading: false,
networkStatus: NetworkStatus.ready,
previousData: undefined,
variables: {},
});

expect(cache.readQuery({ query })).toEqual({ hello: "hello 2" });
});
});
Expand Down

0 comments on commit 475e5b0

Please sign in to comment.