title: Mock javascript function imported from vue
body: <p>I'm trying to set up tests for a vue component <code>collector</code> which is importing a Javascript module to collect some data.</p>
  
  <p><strong>components/collector.vue</strong>
  </p>
  
  <pre><code>&lt;script&gt;
  import dataService from '@/services/dataService.js';
  ...
  
  dataService.collectResults().then(results =&gt; {
    this.data = results;
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>The javascript file:</p>
  
  <p><strong>services/dataService.js</strong></p>
  
  <pre><code>let dataService = {
      collectResults() {
          [...]
          return dataPromise;
      }
      [...]
  } 
  export default dataService;
  </code></pre>
  
  <p>I'm using <code>jest</code> for the tests for the <code>collector</code> component, and trying to mock the <code>collectResults</code> method.</p>
  
  <p><strong>collector.spec.js</strong></p>
  
  <pre><code>jest.mock('dataService');
  import { mount } from '@vue/test-utils';
  import collector from '@/components/collector.vue';
  import VueRouter from 'vue-router';
  
  
  describe('behaviour tests', () =&gt; {
    let cmp;
    beforeEach(() =&gt; {
      Vue.use(VueRouter);
      const router = new VueRouter();
      cmp = mount(collector, {
        router
      });
  
  it('dummy test', () =&gt; {
    console.log(cmp.vm.data);
  }
  </code></pre>
  
  <p><strong>services/__mocks__/dataService.js</strong></p>
  
  <pre><code>const dataServiceMock = jest.genMockFromModule('dataService');
  
  function __collectResults() {
    return new Promise(() =&gt; {
      console.log('mocked!');
      [...]
    });
  }
  
  dataServiceMock.collectResults = __collectResults;
  export default dataServiceMock;
  </code></pre>
  
  <p>However, when running the tests the original <code>dataService.js</code> file is being executed (which in my case leads to an exception).</p>
  
  <p>What should be the correct approach to this case, considering that I've to mock ~10 functions while leaving others as they are?</p>