title: Jest 'TypeError: is not a function' in jest.mock
body: <p>I'm writing a Jest mock, but I seem to have a problem when defining a mocked function outside of the mock itself.</p>
  <p>I have a class:</p>
  <pre><code>myClass.js
  
  class MyClass {
    constructor(name) {
      this.name = name;
    }
  
    methodOne(val) {
      return val + 1;
    }
  
    methodTwo() {
      return 2;
    }
  }
  
  export default MyClass;
  </code></pre>
  <p>And a file using it:</p>
  <pre><code>testSubject.js
  
  import MyClass from './myClass';
  
  const classInstance = new MyClass('Fido');
  
  const testSubject = () =&gt; classInstance.methodOne(1) + classInstance.name;
  
  export default testSubject;
  </code></pre>
  <p>And the test:</p>
  <pre><code>testSubject.test.js
  
  import testSubject from './testSubject';
  
  const mockFunction = jest.fn(() =&gt; 2)
  
  jest.mock('./myClass', () =&gt; () =&gt; ({
      name: 'Name',
      methodOne: mockFunction,
      methodTwo: jest.fn(),
  }))
  
  
  describe('MyClass tests', () =&gt; {
      it('test one', () =&gt; {
          const result = testSubject()
  
          expect(result).toEqual('2Name')
      })
  })
  </code></pre>
  <p>However, I get the following error:</p>
  <blockquote>
  <p>TypeError: classInstance.methodOne is not a function</p>
  </blockquote>
  <p>If I instead write:</p>
  <pre><code>...
  methodOne: jest.fn(() =&gt; 2)
  </code></pre>
  <p>Then the test passes no problem.</p>
  <p>Is there a way of defining this outside of the mock itself?</p>