title: Jest mock is undefined when inspecting it
body: <p>I have a module that uses a second module. They're both custom modules, not NPM packages.</p>
  
  <p>I want to make sure that <code>moduleUnderTest</code> calls a specific method from <code>foo</code>.</p>
  
  <p>So I'm using <code>jest.mock</code> and I pass it a function that has the same signature as <code>foo</code> but contains jest spy functions instead of the actual implementation.</p>
  
  <p>I was under the impression that using <code>jest.mock</code> with the <code>mockFoo</code> object would inject the mocked <code>foo</code> instead of the actual module when <code>moduleUnderTest</code> requires <code>foo</code>.</p>
  
  <p>If I inspect what <code>foo</code> is from within <code>moduleUnderTest</code> while the test is running, I can see that it is indeed my mocked foo.</p>
  
  <p>But when I get to the <code>expect</code>, <code>mockedFoo.met1</code> becomes undefined.</p>
  
  <p>Why is that?</p>
  
  <pre><code>// ../foo/foo.js
  const foo = arg =&gt; {
    console.log(arg)
    return {
      met1: () =&gt; {},
      met2: () =&gt; {},
    }
  }
  
  module.exports = foo
  
  // ..foo/index.js
  // I am doing it this way so I can put the actual implementation in 
  // several different files, but can require the whole module with 
  // require('../foo') rather than require('../foo/foo')
  module.exports = require('./foo')
  
  // ./moduleUnderTest.js
  const foo = require('../foo')('hi')
  
  require('util').inspect(foo) // it seems that foo is indeed the mocked
    // version here[0]
  
  const moduleUnderTest = () =&gt; {
    foo.met1()
  }
  
  module.exports = moduleUnderTest
  
  // ./moduleUnderTest.test.js
  const moduleUnderTest = require('./moduleUnderTest')
  const mockFoo = () =&gt; ({
    met1: jest.fn(),
    met2: jest.fn(),
  })
  jest.mock('../foo')
  
  test('foo.met1 is called', () =&gt; {
    moduleUnderTest()
  
    expect(mockFoo.met1).toHaveBeenCalledTimes(1) // NOPE![1] 
  })
  
  // [0]
  //   { met1: 
  //     { [Function: mockConstructor]
  //       _isMockFunction: true,
  //       getMockImplementation: [Function],
  //       mock: [Getter/Setter],
  //       mockClear: [Function],
  //       mockReset: [Function],
  //       mockReturnValueOnce: [Function],
  //       mockResolvedValueOnce: [Function],
  //       mockRejectedValueOnce: [Function],
  //       mockReturnValue: [Function],
  //       mockResolvedValue: [Function],
  //       mockRejectedValue: [Function],
  //       mockImplementationOnce: [Function],
  //       mockImplementation: [Function],
  //       mockReturnThis: [Function],
  //       mockName: [Function],
  //       getMockName: [Function],
  //       mockRestore: [Function] },
  //    met2: 
  //     { [Function: mockConstructor]
  //       _isMockFunction: true,
  //       getMockImplementation: [Function],
  //       mock: [Getter/Setter],
  //       mockClear: [Function],
  //       mockReset: [Function],
  //       mockReturnValueOnce: [Function],
  //       mockResolvedValueOnce: [Function],
  //       mockRejectedValueOnce: [Function],
  //       mockReturnValue: [Function],
  //       mockResolvedValue: [Function],
  //       mockRejectedValue: [Function],
  //       mockImplementationOnce: [Function],
  //       mockImplementation: [Function],
  //       mockReturnThis: [Function],
  //       mockName: [Function],
  //       getMockName: [Function],
  //       mockRestore: [Function] } }
  
  // [1]
  //  expect(jest.fn())[.not].toHaveBeenCalledTimes()
  //  
  //  jest.fn() value must be a mock function or spy.
  //  Received: undefined
  </code></pre>