Skip to content

Commit

Permalink
undo some React17 specific changes
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Nov 29, 2024
1 parent 161c540 commit ddcf14c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 46 deletions.
11 changes: 1 addition & 10 deletions src/react/hooks/__tests__/useFragment.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import userEvent from "@testing-library/user-event";
import { act } from "@testing-library/react";

import { UseFragmentOptions, useFragment } from "../useFragment";
import { MockedProvider, wait } from "../../../testing";
import { MockedProvider } from "../../../testing";
import { ApolloProvider } from "../../context";
import {
InMemoryCache,
Expand Down Expand Up @@ -1515,9 +1515,6 @@ describe("useFragment", () => {
});
}

// necessary for React 17
await wait(0);

client.writeFragment({
fragment,
data: {
Expand Down Expand Up @@ -1595,9 +1592,6 @@ describe("useFragment", () => {
});
}

// necessary for React 17
await wait(0);

client.writeFragment({
fragment,
fragmentName: "PostFragment",
Expand Down Expand Up @@ -1832,9 +1826,6 @@ describe("has the same timing as `useQuery`", () => {
expect(snapshot.fragmentData).toStrictEqual({});
}

// necessary for React 17
await wait(10);

assert(observer!);
observer.next({ data: { item: initialItem } });
observer.complete();
Expand Down
42 changes: 15 additions & 27 deletions src/react/hooks/__tests__/useLazyQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
renderHookToSnapshotStream,
} from "@testing-library/react-render-stream";

const IS_REACT_17 = React.version.startsWith("17");
describe("useLazyQuery Hook", () => {
const helloQuery: TypedDocumentNode<{
hello: string;
Expand Down Expand Up @@ -1136,14 +1135,11 @@ describe("useLazyQuery Hook", () => {
);
}

if (!IS_REACT_17) {
// in React 17 with RTL 16, this promise never resolves??
await executePromise.then((result) => {
expect(result.loading).toBe(false);
expect(result.data).toBeUndefined();
expect(result.error!.message).toBe("error 1");
});
}
await executePromise.then((result) => {
expect(result.loading).toBe(false);
expect(result.data).toBeUndefined();
expect(result.error!.message).toBe("error 1");
});

execute();

Expand Down Expand Up @@ -1951,11 +1947,6 @@ describe("useLazyQuery Hook", () => {

// regression for https://github.com/apollographql/apollo-client/issues/11988
test("calling `clearStore` while a lazy query is running puts the hook into an error state and resolves the promise with an error result", async () => {
if (IS_REACT_17) {
// this test is currently broken in React 17 with RTL 16 and needs further investigation
return;
}

const link = new MockSubscriptionLink();
let requests = 0;
link.onSetup(() => requests++);
Expand Down Expand Up @@ -1989,19 +1980,16 @@ describe("useLazyQuery Hook", () => {

client.clearStore();

if (!IS_REACT_17) {
// in React 17 with RTL 16, this promise never resolves??
const executionResult = await promise;
expect(executionResult.data).toBeUndefined();
expect(executionResult.loading).toBe(true);
expect(executionResult.error).toEqual(
new ApolloError({
networkError: new InvariantError(
"Store reset while query was in flight (not completed in link chain)"
),
})
);
}
const executionResult = await promise;
expect(executionResult.data).toBeUndefined();
expect(executionResult.loading).toBe(true);
expect(executionResult.error).toEqual(
new ApolloError({
networkError: new InvariantError(
"Store reset while query was in flight (not completed in link chain)"
),
})
);

{
const [, result] = await takeSnapshot();
Expand Down
5 changes: 1 addition & 4 deletions src/react/hooks/__tests__/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6935,10 +6935,7 @@ describe("useQuery Hook", () => {
}

const calls = consoleSpy.error.mock.calls;
if (!IS_REACT_17) {
// React 17 doesn't know `IS_REACT_ACT_ENVIRONMENT` yet, so it will log a warning that we don't care about.
expect(calls.length).toBe(1);
}
expect(calls.length).toBe(1);
expect(calls[0][0]).toMatch("Missing field");

{
Expand Down
8 changes: 3 additions & 5 deletions src/react/hooks/__tests__/useSubscription.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { PROTOCOL_ERRORS_SYMBOL } from "../../../errors";
import { InMemoryCache as Cache } from "../../../cache";
import { ApolloProvider } from "../../context";
import { MockSubscriptionLink, wait } from "../../../testing";
import { MockSubscriptionLink } from "../../../testing";
import { useSubscription } from "../useSubscription";
import { spyOnConsole } from "../../../testing/internal";
import { SubscriptionHookOptions } from "../../types/types";
Expand Down Expand Up @@ -631,10 +631,9 @@ describe("useSubscription Hook", () => {
expect(result.current.error).toBe(undefined);
expect(result.current.data).toBe(undefined);

// Simulating the behavior of HttpLink, which calls next and complete in sequence.
await act(async () => {
// Simulating the behavior of HttpLink, which calls next and complete in sequence.
link.simulateResult({ result: { data: null } }, /* complete */ true);
await wait(10);
});

await waitFor(
Expand Down Expand Up @@ -693,10 +692,9 @@ describe("useSubscription Hook", () => {
expect(result.current.sub3.error).toBe(undefined);
expect(result.current.sub3.data).toBe(undefined);

// Simulating the behavior of HttpLink, which calls next and complete in sequence.
await act(async () => {
// Simulating the behavior of HttpLink, which calls next and complete in sequence.
link.simulateResult({ result: { data: null } }, /* complete */ true);
await wait(10);
});

await waitFor(
Expand Down

0 comments on commit ddcf14c

Please sign in to comment.