title: Mocking single function from a module which also calls it from another function, jest, typescript
body: <p>I have module with two functions:</p>
  <pre><code>
  export const functionReturnsOne = () =&gt; {
      return 1;
  };
  export const functionReturnsTwo = () =&gt; {
      return functionReturnsOne() + functionReturnsOne();
  };
  </code></pre>
  <p>Now I would like to mock <code>functionReturnsOne</code> but keep original <code>functionReturnsTwo</code></p>
  <p>Here is the test:</p>
  <pre><code>import { functionReturnsTwo, functionReturnsOne } from '../testModule';
  
  jest.mock('../testModule', () =&gt; {
      const actualTestModule = jest.requireActual('../testModule');
      return {
          ...actualTestModule,
          functionReturnsOne: jest.fn()
      };
  });
  
  describe('testModule', () =&gt; {
      test('when functionReturnsOne is mocked but functionReturnsTwo is not', () =&gt; {
          const mockFunctionReturnsOne = functionReturnsOne as jest.Mock;
          mockFunctionReturnsOne.mockReturnValue(13);
  
          const result1 = functionReturnsOne();
          const result2 = functionReturnsTwo();
  
          expect(result1).toBe(13);
          expect(result2).toBe(26);
      });
  });
  </code></pre>
  <p>After running the test, <code>result1</code> contains <code>13</code> as expected, so mock for <code>functionReturnsOne</code> worked. But <code>result2</code> contains <code>2</code> which means this function called not mocked version of <code>functionReturnsOne</code>.</p>
  <p>Is there elegant way (not splitting into separate files and no dependency injection) to call original <code>functionReturnsTwo</code> that would call mocked version of <code>functionReturnsOne</code>?</p>