Have ideas to improve npm?Join in the discussion! »

    @shopify/jest-mock-apollo
    TypeScript icon, indicating that this package has built-in type declarations

    5.1.9 • Public • Published

    @shopify/jest-mock-apollo

    Build Status Build Status License: MIT npm version

    ⚠️ This is being replaced with @shopify/graphql-testing

    Jest + Enzyme mocks for Apollo 2.x.

    Installation

    $ yarn add @shopify/jest-mock-apollo

    Setup

    This package provides a decorator for building mock GraphQL clients specific to your project. The initial function call takes in project-wide configuration and emits a customized decorator to be used across your project. For example:

    // tests/utilities/graphql.ts
    import {buildSchema} from 'graphql';
    import configureClient from '@shopify/jest-mock-apollo';
    
    // You likely want to import this from somewhere in real production code
    const schemaSrc = `
      type Product {
        id: Int!
        title: String
      }
    
      type Query {
        products: [Product]
      }
    `;
    const schema = buildSchema(schemaSrc);
    
    const createGraphQLClient = configureClient({schema});
    
    export {createGraphQLClient};

    The factory requires a GraphQLSchema (schema) in order to ensure that more useful error messages are shown and that mocks are validated against the schema.

    Example Usage

    Take a look at the test suite for examples on how to use enzyme's mock context.

    API Reference

    See the comments and TypeScript annotations in the code for details on the provided utilities.

    Keywords

    none

    Install

    npm i @shopify/jest-mock-apollo

    DownloadsWeekly Downloads

    32,469

    Version

    5.1.9

    License

    MIT

    Unpacked Size

    69.2 kB

    Total Files

    55

    Last publish

    Collaborators

    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar