title: How to mock vue composable functions with jest
body: <p>I'm using vue2 with composition Api, vuex and apollo client to request a graphql API and I have problems when mocking composable functions with jest</p>
  <pre><code>// store-service.ts
  export function apolloQueryService(): { 
    
    // do some graphql stuff
  
    return { result, loading, error };
  }
  
  </code></pre>
  <pre><code>// store-module.ts
  import { apolloQueryService } from 'store-service'
  
  export StoreModule {
    state: ()=&gt; ({
      result: {}
    }),
    actions: {
      fetchData({commit}) {
        const { result, loading, error } = apolloQueryService()
        commit('setState', result);
      }
    },
    mutations: {
      setState(state, result): {
        state.result = result
      }
    }
  }
  </code></pre>
  <p>The Test:</p>
  <pre><code>// store-module.spec.ts
  import { StoreModule } from store-module.ts
  
  const store = StoreModule 
  describe('store-module.ts', () =&gt; {
    beforeEach(() =&gt; {
      jest.mock('store-service', () =&gt; ({
        apolloQueryService: jest.fn().mockReturnValue({ 
          result: { value: 'foo' }, loading: false, error: {} 
        })
      }))
    })
  
    test('action', async ()=&gt; {
      const commit = jest.fn();
      await store.actions.fetchData({ commit });
      expect(commit).toHaveBeenCalledWith('setData', { value: 'foo' });
    })
  }
  </code></pre>
  <p>The test fails, because the commit gets called with ('setData', { value: undefined }) which is the result from the original apolloQueryService. My Mock doesn't seem to work. Am I doing something wrong? Appreciate any help, thanks!</p>