title: Use imported variables in jest mock function
body: <p>I am mocking a function from a file which uses <code>moment</code>, Here is the file contents:</p>
  
  <p>./utils/dateUtils:</p>
  
  <pre><code>import moment from 'moment-timezone'
  
  export function getToday() {
    return moment().tz(commonTimeZone)
  }
  </code></pre>
  
  <p><br />
  ./containers/someContainer.js:</p>
  
  <pre><code>import { getToday } from 'utils/dateUtils'
  
  // Uses getToday in the component
  </code></pre>
  
  <p><br />
  ./containers/someContainer.spec.js:</p>
  
  <pre><code>import moment from 'moment-timezone'
  
  jest.mock('utils/dateUtils', () =&gt; {
    return {
      getToday : moment(new Date('2018-01-01'))
    }
  })
  </code></pre>
  
  <p>test throws this error:</p>
  
  <pre><code>● Test suite failed to run
  
      /Users/bharat/Documents/redmart-repo/partner-portalv2/app/containers/Orders/PickupsContainer.test.js: babel-plugin-jest-hoist: The module factory of `jest.mock()` is not allowed to reference any out-of-scope variables.
      Invalid variable access: moment
      Whitelisted objects: Array, ArrayBuffer, Boolean, DataView, Date, Error, EvalError, Float32Array, Float64Array, Function, Generator, GeneratorFunction, Infinity, Int16Array, Int32Array, Int8Array, InternalError, Intl, JSON, Map, Math, NaN, Number, Object, Promise, Proxy, RangeError, ReferenceError, Reflect, RegExp, Set, String, Symbol, SyntaxError, TypeError, URIError, Uint16Array, Uint32Array, Uint8Array, Uint8ClampedArray, WeakMap, WeakSet, arguments, expect, jest, require, undefined, DTRACE_NET_SERVER_CONNECTION, DTRACE_NET_STREAM_END, DTRACE_HTTP_SERVER_REQUEST, DTRACE_HTTP_SERVER_RESPONSE, DTRACE_HTTP_CLIENT_REQUEST, DTRACE_HTTP_CLIENT_RESPONSE, global, process, Buffer, clearImmediate, clearInterval, clearTimeout, setImmediate, setInterval, setTimeout, console.
      Note: This is a precaution to guard against uninitialized mock variables. If it is ensured that the mock is required lazily, variable names prefixed with `mock` are permitted.
  
        at invariant (node_modules/babel-plugin-jest-hoist/build/index.js:12:11)
        at newFn (node_modules/babel-traverse/lib/visitors.js:276:21)
        at NodePath._call (node_modules/babel-traverse/lib/path/context.js:76:18)
        at NodePath.call (node_modules/babel-traverse/lib/path/context.js:48:17)
        at NodePath.visit (node_modules/babel-traverse/lib/path/context.js:105:12)
        at TraversalContext.visitQueue (node_modules/babel-traverse/lib/context.js:150:16)
        at TraversalContext.visitMultiple (node_modules/babel-traverse/lib/context.js:103:17)
  </code></pre>
  
  <p>Not sure what am missing here, does someone know how to fix this error.</p>
  
  <p>P.S. I tried <code>jest.doMock</code> but it doesn't mock anything.</p>