Skip to content

Commit

Permalink
Fix issue with React 18 in test
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jan 10, 2025
1 parent a8e3dfe commit 0ea807d
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/react/hooks/__tests__/useLazyQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
renderHookToSnapshotStream,
} from "@testing-library/react-render-stream";

const IS_REACT_18 = React.version.startsWith("18");

describe("useLazyQuery Hook", () => {
const helloQuery: TypedDocumentNode<{
hello: string;
Expand Down Expand Up @@ -359,7 +361,7 @@ describe("useLazyQuery Hook", () => {
},
});
observer.complete();
}, 10);
}, 50);
} else {
observer.error(
new Error(
Expand Down Expand Up @@ -539,6 +541,21 @@ describe("useLazyQuery Hook", () => {
expect(result).not.toHaveProperty("errors");
}

// For some reason we get an extra render in React 18 of the same thing
if (IS_REACT_18) {
const [, result] = await takeSnapshot();

expect(result).toMatchObject({
data: { counter: 2, vars: { execVar: false } },
called: true,
loading: true,
networkStatus: NetworkStatus.setVariables,
previousData: { counter: 2, vars: { execVar: false } },
});
expect(result).not.toHaveProperty("error");
expect(result).not.toHaveProperty("errors");
}

{
const [, result] = await takeSnapshot();

Expand Down

0 comments on commit 0ea807d

Please sign in to comment.