title: How to mock client.readQuery from Apollo 2 in Jest
body: <p>There's a component which I am using the cache that I created in apollo, stored inside the <code>client</code>.</p>
  
  <p>At some point, as a callback from an input, I do the following call:</p>
  
  <pre><code>const originalName = client.readQuery&lt;NamesCached&gt;({ query: NamesCached })!.names
  </code></pre>
  
  <p>this returns directly an array of objects.</p>
  
  <p>However, I do not know how to test this in my component. My first assumption was to mock exclusively the <code>client.readQuery</code> to return me an array from my <code>__fixtures__</code>. That didn't work.</p>
  
  <p>Here is my best shot to mock it:</p>
  
  <pre><code>it('filters the name in the search', () =&gt; {
    jest.doMock('@/ApolloClient', () =&gt; ({
      readQuery: jest.fn()
    }))
    const client = require('@/ApolloClient')
    client.readQuery.mockImplementation(()=&gt; Promise.resolve(names()))
  
    const { getByPlaceholderText, queryByText } = renderIndexNames()
    const input = getByPlaceholderText('Search…')
  
    fireEvent.change(input, { target: { value: 'Second Name' } })
  
    expect(queryByText('Title for a name')).not.toBeInTheDocument()
  })
  
  </code></pre>
  
  <p>For this test I am using <code>react-testing-library</code>. This is my best shot so far...</p>
  
  <pre><code>jest.doMock('@/ApolloClient', () =&gt; ({
      readQuery: jest.fn()
    }))
    const client = require('@/ApolloClient')
    client.readQuery.mockImplementation(()=&gt; Promise.resolve(names()))
  </code></pre>
  
  <p>It is important that relies on a single IT, not on the top since there are other tests that are using the client and works properly. 
  With That I could had mocked in the test when invokin <code>client.readQuery()</code> but then in the component itself goes back to its own original state</p>
  
  <p><strong>My goal</strong>
  Find a way that the <code>client.readQuery</code> can be mocked and return the data I am looking for. I thought in mocking, but any other solution that can work for a single or group of tests( without all of them) would be more than welcome.</p>
  
  <p>I tried as well mocking on the top, but then the others are failing and i couldn't reproduce to go back to the real implementation</p>