Skip to content

Commit

Permalink
Add explicit generic arguments to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Dec 20, 2024
1 parent 972805d commit b727b1d
Showing 1 changed file with 44 additions and 10 deletions.
54 changes: 44 additions & 10 deletions src/react/hooks/__tests__/useSuspenseFragment.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1783,24 +1783,47 @@ test("cancels autoDisposeTimeoutMs if the component renders before timer finishe

describe.skip("type tests", () => {
test("returns TData when from is a non-null value", () => {
const fragment: TypedDocumentNode<{ foo: string }> = gql``;
type Data = { foo: string };
const fragment: TypedDocumentNode<Data> = gql``;

const { data } = useSuspenseFragment({
fragment,
from: { __typename: "Query" },
});
{
const { data } = useSuspenseFragment({
fragment,
from: { __typename: "Query" },
});

expectTypeOf(data).branded.toEqualTypeOf<{ foo: string }>();
expectTypeOf(data).branded.toEqualTypeOf<Data>();
}

{
const { data } = useSuspenseFragment<Data>({
fragment: gql``,
from: { __typename: "Query" },
});

expectTypeOf(data).branded.toEqualTypeOf<Data>();
}
});

test("returns TData | null when from is null", () => {
type Data = { foo: string };
type Vars = Record<string, never>;
const fragment: TypedDocumentNode<Data, Vars> = gql``;

const { data } = useSuspenseFragment({ fragment, from: null });
{
const { data } = useSuspenseFragment({ fragment, from: null });

expectTypeOf(data).branded.toEqualTypeOf<null>();
expectTypeOf(data).branded.toEqualTypeOf<null>();
}

{
const { data } = useSuspenseFragment<Data>({
fragment: gql``,
from: null,
});

expectTypeOf(data).branded.toEqualTypeOf<null>();
}
});

test("returns TData | null when from is nullable", () => {
Expand All @@ -1809,8 +1832,19 @@ describe.skip("type tests", () => {
const fragment: TypedDocumentNode<Post, Vars> = gql``;
const author = {} as { post: Post | null };

const { data } = useSuspenseFragment({ fragment, from: author.post });
{
const { data } = useSuspenseFragment({ fragment, from: author.post });

expectTypeOf(data).branded.toEqualTypeOf<Post | null>();
expectTypeOf(data).branded.toEqualTypeOf<Post | null>();
}

{
const { data } = useSuspenseFragment<Post>({
fragment: gql``,
from: author.post,
});

expectTypeOf(data).branded.toEqualTypeOf<Post | null>();
}
});
});

0 comments on commit b727b1d

Please sign in to comment.