Skip to content

Commit

Permalink
Add test for useQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuanapoli committed Nov 5, 2023
1 parent 97bd861 commit df6d62a
Showing 1 changed file with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
// @flow

import { describe, it } from 'flow-typed-test';
import { ApolloCache, ApolloClient, ApolloLink, ApolloProvider, createHttpLink, useSubscription } from '@apollo/client';
import {
ApolloCache,
ApolloClient,
ApolloLink,
ApolloProvider,
createHttpLink,
useQuery,
useSubscription,
} from '@apollo/client';
import type { FetchResult, OnSubscriptionDataOptions, Operation } from '@apollo/client';
import { MockedProvider } from "@apollo/client/testing";
import { onError } from "@apollo/client/link/error";
Expand Down Expand Up @@ -91,6 +99,36 @@ describe('useSubscription', () => {
});
});

type DataType = {|
id: string,
|};

describe('useQuery', () => {
const validVariables = { myVar: 'foo' };

it('accepts correct data and variables type', () => {
const testFun = (query: DocumentNode) => {
const { data } = useQuery<DataType, typeof validVariables>(query, {
fetchPolicy: "cache-first",
variables: validVariables
});
const myData: ?DataType = data;
};
});

it('rejects incorrect variables type', () => {
const invalidVariables = { wrong: 'type' };
const testFun = (query: DocumentNode) => {
const { data } = useQuery<DataType, typeof validVariables>(query, {
fetchPolicy: "cache-first",
// $FlowExpectedError[prop-missing]
variables: invalidVariables
});
const myData: ?DataType = data;
};
});
});

describe('ApolloProvider', () => {
it('accepts a client and children', () => {
<ApolloProvider client={client} ><div /></ApolloProvider>;
Expand Down Expand Up @@ -165,6 +203,7 @@ describe("getMainDefinition utility", () => {
const operation: string = definition.operation;
} else {
// $FlowExpectedError[prop-missing]
// $FlowExpectedError[incompatible-type]
const operation: string = definition.operation;
}
}
Expand Down

0 comments on commit df6d62a

Please sign in to comment.