title: Mock new Function() with Jest
body: <p>I'm having trouble trying to mock a module with a constructor</p>
  
  <pre><code>// code.js
  const ServiceClass = require('service-library');
  const serviceInstance = new ServiceClass('some param');
  exports.myFunction = () =&gt; {
    serviceInstance.doSomething();
  };
  </code></pre>
  
  <p>And the test code:</p>
  
  <pre><code>// code.test.js
  const ServiceClass = require('service-library');
  jest.mock('service-library');
  const {myFunction} = require('../path/to/my/code');
  
  test('check that the service does something', () =&gt; {
    // ????
  });
  </code></pre>
  
  <p>It's not like the Documentation example <a href="https://jestjs.io/docs/en/mock-functions#mocking-modules" rel="noreferrer">Mocking Modules</a> because you need to instantiate the module after importing it. And isn't either like Mocking a Function.</p>
  
  <p>How could I mock this <code>doSomething()</code> function while testing?</p>
  
  <p>For reference, I'm trying to mock <code>@google-cloud/*</code> packages here. And I have a few projects that could take advantage on this.</p>