Skip to content

Commit

Permalink
apollo-client: Add tests for ApolloClient initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
stackpathtladd2 committed May 12, 2018
1 parent c30a426 commit aea7959
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
declare module "apollo-client" {
import type {
DocumentNode,
ExecutionResult,
GraphQLError,
SelectionSetNode,
FieldNode,
InlineFragmentNode,
ValueNode,
SelectionNode,
NameNode
// $FlowFixMe - Can't import types from node_modules at the moment
} from "graphql";
// These types are from the graphql module. No way to import them at the moment
declare type DocumentNode = any;
declare type ExecutionResult = any;
declare type GraphQLError = any;

declare export function print(ast: any): string;

Expand Down Expand Up @@ -403,9 +395,9 @@ declare module "apollo-client" {
}

declare interface DefaultOptions {
watchQuery?: ModifiableWatchQueryOptions;
query?: ModifiableWatchQueryOptions;
mutate?: MutationBaseOptions<>;
+watchQuery?: ModifiableWatchQueryOptions;
+query?: ModifiableWatchQueryOptions;
+mutate?: MutationBaseOptions<>;
}

declare export type ApolloClientOptions<TCacheShape> = {
Expand Down Expand Up @@ -582,7 +574,7 @@ declare module "apollo-client" {
/* End TODO: Move to apollo-link libdef */

/* TODO: Move these types to apollo-cache libdef */
declare class ApolloCache<TSerialized> {
declare export class ApolloCache<TSerialized> {
read<T>(query: CacheReadOptions): T | null;
write(write: CacheWriteOptions): void;
diff<T>(query: CacheDiffOptions): CacheDiffResult<T>;
Expand Down
97 changes: 97 additions & 0 deletions definitions/npm/apollo-client_v2.x.x/test_apollo-client_v2.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// @flow

import { ApolloClient, ApolloLink, ApolloCache } from "apollo-client";
import { describe, it } from "flow-typed-test";

const link = new ApolloLink();
const cache = new ApolloCache();

describe("apollo-client", () => {
describe("ApolloClient initialization", () => {
it("passes when passed correct configuration", () => {
new ApolloClient({
link,
cache
});
});

it("passes when passed optional cnfig options", () => {
new ApolloClient({
link,
cache,
ssrMode: true,
ssrForceFetchDelay: 1000,
connectToDevTools: true,
queryDeduplication: true,
defaultOptions: {
query: {
fetchPolicy: "cache-and-network"
}
}
});
});

it("raises error when missing link", () => {
// $ExpectError - link required to initialize ApolloClient
new ApolloClient({
cache
});
});

it("raises error when missing cache", () => {
// $ExpectError - cache required to initialize ApolloClient
new ApolloClient({
link
});
});

it("raises error when passing invalid connectToDevTools", () => {
// $ExpectError - connectToDevTools must be boolean
new ApolloClient({
link,
cache,
connectToDevTools: "true"
});
});

it("raises error when passing invalid ssrMode", () => {
// $ExpectError - ssrMode must be boolean
new ApolloClient({
link,
cache,
ssrMode: "true"
});
});

it("raises error when passing invalid ssrForceFetchDelay", () => {
// $ExpectError - ssrForceFetchDelay must be number
new ApolloClient({
link,
cache,
ssrForceFetchDelay: "true"
});
});

it("raises error when passing invalid queryDeduplication", () => {
// $ExpectError - queryDeduplication must be boolean
new ApolloClient({
link,
cache,
queryDeduplication: "true"
});
});

it("raises error when passing invalid defaultOptions", () => {
// $ExpectError - defaultOptions fetchPolicy is invalid
new ApolloClient({
link,
cache,
defaultOptions: {
query: {
fetchPolicy: "invalidFetchPolicy"
}
}
});
});
});
});

0 comments on commit aea7959

Please sign in to comment.