How to use mock-apollo-client - 3 common examples

To help you get started, we’ve selected a few mock-apollo-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gitlabhq / gitlabhq / spec / frontend / __helpers__ / mock_apollo_helper.js View on Github external
export function createMockClient(handlers = [], resolvers = {}, cacheOptions = {}) {
  const cache = new InMemoryCache({
    ...defaultCacheOptions,
    ...cacheOptions,
  });

  const mockClient = createMockApolloClient({ cache, resolvers });

  if (Array.isArray(handlers)) {
    handlers.forEach(([query, value]) => mockClient.setRequestHandler(query, value));
  } else {
    throw new Error('You should pass an array of handlers to mock Apollo client');
  }

  return mockClient;
}
github gitlabhq / gitlabhq / spec / frontend / import_entities / import_groups / graphql / client_factory_spec.js View on Github external
const createClient = (extraResolverArgs) => {
    return createMockClient({
      cache: new InMemoryCache({
        fragmentMatcher: { match: () => true },
        addTypename: false,
      }),
      resolvers: createResolvers({ endpoints: FAKE_ENDPOINTS, ...extraResolverArgs }),
    });
  };
github alexieyizhe / intern.plus / src / api / client / mock.ts View on Github external
{
    query: getSearchBuilder({
      type: SearchType.REVIEWS,
      sort: SearchSort.SALARY,
    }),
    handler: (params: ISearchQueryParams) =>
      Promise.resolve({
        data: getMockAllSearch(params, {
          type: SearchType.REVIEWS,
          sort: SearchSort.SALARY,
        }),
      }),
  },
];

const mockClient = createMockClient();

export default mockClient;

API_CALLS.forEach(call => {
  mockClient.setRequestHandler(call.query, call.handler);
});

mock-apollo-client

Library to help unit testing when using apollo-client

MIT
Latest version published 8 months ago

Package Health Score

63 / 100
Full package analysis

Popular mock-apollo-client functions