Apollo Client Mock
Easily mock your apollo client for testing. It uses Apollo Link Schema under the surface
Installation
$ npm install --save-dev apollo-client-mock
Setup
To setup Apollo mock client you need to import your schema in as well as your mock resolvers. Then you can setup your client with these two arguments which will then return a createClient
function which you can create a mockedClient for each test. createClient
can optionally take a new set of resolvers that can overwrite your defaults
const defaultMocks = //...other queries { return name state: 'Open' } //...other mutations const createClient =
//Test file
The following example shows you can overwrite each resolver per test. This is useful if you want to setup a spy for your resolver function to ensure it has been called. This is particularly useful if your component just makes a mutation but does not actually show the result of the state change in the component.