graphql-mock is a declarative mocking library for Apollo GraphQL client testing, inspired by nock/sinon. Version 2.0.0 (latest) provides ESM with TypeScript types. It enables developers to specify exact response data, test failure and loading states, and assert queries/mutations sent by code. Differentiators include seamless integration with react-apollo and react-apollo-hooks, automatic client refresh on reset, and support for variables assertion. Released under MIT license by MadRabbit.
npm install graphql-mockNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic mocking of a GraphQL query with success, failure, and loading states using Enzyme and ApolloProvider.
Always reference graphqlMock.client inside the render function, not outside.
After simulate, add 'await new Promise(r => setTimeout(r, 10)); wrapper.update();' before assertions.
Use import syntax; switch to ESM module configuration.
Upgrade to v2.0.0 and update calls to use .reply(), .fail(), .loading() chains.
Use import { graphqlMock } from 'graphql-mock' or enable ESM in your project.Use import { graphqlMock } from 'graphql-mock' instead of default import.Reference graphqlMock.client directly inside the render function, not via destructured variable.
Ensure query strings are identical (use template literals) and include variables if needed.