title: Passing out-of-scope variable with jest.mock
body: <p>I have a mock object that I am using to mock <code>react-native</code>:</p>
  
  <pre><code>const MyMock = {
      MockA: {
          methodA: jest.genMockFn()
      },
      MockB: {
          ObjectB: {
              methodA: jest.genMockFn(),
              methodB: jest.genMockFn(),
          }
      }
  };
  
  
  jest.mock('react-native', () =&gt; {
      return MyMock;
  });
  </code></pre>
  
  <p>I am declaring the object outside of <code>jest.mock</code> because I also need it later on in my tests:</p>
  
  <pre><code>describe('MyClass', () =&gt; {
       beforeEach(() =&gt; {
           MyMock.MockB.ObjectB.methodA.mockClear();
           MyMock.MockB.ObjectB.methodB.mockClear();
       });
       //some other code
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>The module factory of <code>jest.mock()</code> is not allowed to reference any out-of-scope variables.</p>
  </blockquote>
  
  <p>The problem is that I declare <code>MyMock</code> outside of <code>jest.mock</code>. But I have no choice as far as I can see.</p>
  
  <p>So how can I make the code work while keeping <code>MyMock</code> outside of <code>jest.mock</code>?</p>