Skip to content

Commit

Permalink
use mockFetchQuery helper in test
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Jul 8, 2024
1 parent 15131cd commit bb7aaf3
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/react/hooks/__tests__/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
} from "../../../testing/internal";
import { useApolloClient } from "../useApolloClient";
import { useLazyQuery } from "../useLazyQuery";
import { mockFetchQuery } from "../../../core/__tests__/ObservableQuery";

const IS_REACT_17 = React.version.startsWith("17");

Expand Down Expand Up @@ -7097,21 +7098,14 @@ describe("useQuery Hook", () => {
link,
});

const fetchQueryByPolicySpy = jest.spyOn(
client["queryManager"] as any as {
fetchQueryByPolicy(
info: {},
options: { fetchPolicy: WatchQueryFetchPolicy }
): unknown;
},
"fetchQueryByPolicy"
);
const mocks = mockFetchQuery(client["queryManager"]);

const expectQueryTriggered = (
nth: number,
fetchPolicy: WatchQueryFetchPolicy
) => {
expect(fetchQueryByPolicySpy).toHaveBeenCalledTimes(nth);
expect(fetchQueryByPolicySpy).toHaveBeenNthCalledWith(
expect(mocks.fetchQueryByPolicy).toHaveBeenCalledTimes(nth);
expect(mocks.fetchQueryByPolicy).toHaveBeenNthCalledWith(
nth,
expect.anything(),
expect.objectContaining({ fetchPolicy }),
Expand Down

0 comments on commit bb7aaf3

Please sign in to comment.