title: How to extend Jest mock?
body: <p>In my unit tests (written in Typescript, run by Jest), I want to mock two classes that share common functionality.  For instance they both have <code>tick()</code> and <code>getTicks()</code> methods.  My Jest mocks currently duplicates code to accomplish this, like so:</p>
  
  <pre class="lang-js prettyprint-override"><code>const mock1 = jest.fn(() =&gt; {
    let ticks = 0;
  
    return {
      tick: jest.fn(() =&gt; {ticks++; }),
      getTicks: jest.fn(() =&gt; ticks),
      doSomething: jest.fn()
    }
  });
  
  const mock2 = jest.fn(() =&gt; {
    let ticks = 0;
  
    return {
      tick: jest.fn(() =&gt; {ticks++; }),
      getTicks: jest.fn(() =&gt; ticks),
      doAnotherThing: jest.fn()
    }
  });
  
  </code></pre>
  
  <p>Now I can do:</p>
  
  <pre class="lang-js prettyprint-override"><code>const mock1Instance = new mock1();
  const mock2Instance = new mock2();
  mock1Instance.tick();
  mock2Instance.getTicks();
  </code></pre>
  
  <p>But the duplication seems stupid.  Is there a way for me to declare a base mock, and just extend from it, like:</p>
  
  <pre class="lang-js prettyprint-override"><code>const baseMock = jest.fn(() =&gt; {
    let ticks = 0;
  
    return {
      tick: jest.fn(() =&gt; {ticks++; }),
      getTicks: jest.fn(() =&gt; ticks),
    }
  });
  </code></pre>