title: Mock a typescript interface with jest
body: <p>Is it possible to mock a typescript interface with jest?</p>
  
  <p>For example:</p>
  
  <pre><code>import { IMultiplier } from "./IMultiplier";
  
  export class Math {
    multiplier: IMultiplier;
  
    public multiply (a: number, b: number) {
      return this.multiplier.multiply(a, b);
    }
  }
  </code></pre>
  
  <p>Then in a test:</p>
  
  <pre><code>import { Math } from "../src/Math";
  import { IMultiplier } from "../src/IMultiplier";
  
  describe("Math", () =&gt; {
  
      it("can multiply", () =&gt; {
          let mathlib = new Math();
          mathlib.multiplier = // &lt;--- assign this property a mock
          let result = mathlib.multiply(10, 2);
          expect(result).toEqual(20);
      });
  });
  </code></pre>
  
  <p>I've tried to create a mock object to satisfy this a number of ways, but none work. For example assigning it this mock:</p>
  
  <pre><code>let multiplierMock = jest.fn(() =&gt; ({ multiply: jest.fn() }));
  </code></pre>
  
  <p>Will produce something along the lines of:</p>
  
  <pre><code>Error - Type 'Mock&lt;{ multiply: Mock&lt;{}&gt;; }&gt;' is not assignable to type 'IMultiplier'.
  </code></pre>