jest-serializer-graphql

1.0.0 • Public • Published

Jest serializer to snapshot GraphQL query objects

This serializer formats GraphQL queries returned by gql into human-readable query strings

Example

Component

const mutation = gql`
mutation CreateItem($name: String!) {
  create(name: $name) {
    item {
      id
      name
    }
  }
}
`;

const FormWithMutation = () => (
  <Mutation 
    mutation={mutation}
  >
    <Form />
  </Mutation>
);

Test

expect(shallow(<FormWithMutation />)).toMatchSnapshot();

Snapshot

<Mutation 
  mutation={
    "mutation CreateItem($name: String!) {
       create(name: $name) {
         item {
           id
           name
         }
       }
    }"
  }
>
  <Form />
</Mutation>

Installation and configuration

yarn add jest-serializer-graphql

or

npm install -S jest-serializer-graphql

Add jest-serializer-graphql to snapshotSerializers entry in Jest config.

snapshotSerializers: [
  "jest-serializer-graphql"
]

Package Sidebar

Install

npm i jest-serializer-graphql

Weekly Downloads

231

Version

1.0.0

License

MIT

Unpacked Size

6.37 kB

Total Files

11

Last publish

Collaborators

  • asilis-scout-rfp