title: How to mock a function in Jest
body: <p>I have the following typescript class which I want to test in Jest.</p>
  
  <pre><code>//MyClass.ts
  import { foo } from './somewhere/FooFactory';
  export class MyClass {
    private _state : number;
    constructor( arg : string ) {
      this._state = foo( arg );
    }
  
    public getState() : string {
      return this._state;
    }
  }
  </code></pre>
  
  <p>This is my test:</p>
  
  <pre><code>//MyClass.spec.ts
  import { MyClass } from './MyClass';
  describe( 'test MyClass', () =&gt; {
    test( 'construct' =&gt; {
      const c = new MyClass( 'test' );
      expect( c ).toBeDefined();
      expect( c.getState() ).toEqual( 'TEST' );
    } );
  } );
  </code></pre>
  
  <p>How do I mock the foo function used inside MyClass so that this test passes?</p>