title: Set moment timezone in Jest tests
body: <p>I have the util function that is parsing given date (i.e. '2019-01-28') in specific date format and then using <code>momentJS</code> retrieving beginning of that day and converting it to ISO date format:</p>
  
  <p><strong>dates.js</strong></p>
  
  <pre><code>import moment from 'moment'
  
  export const getApiDateFormat = (date, dateFormat = getLocaleDateString()) =&gt;
      moment(date, dateFormat)
        .startOf('day')
        .toISOString()
  </code></pre>
  
  <p>I would like to test this function using <code>Jest</code> and set the specific timezone for <code>moment</code> to use those tests independent of my location.</p>
  
  <p>For now, I have:</p>
  
  <p><strong>dates.test.js</strong></p>
  
  <pre><code>const formattedDate = '2019-01-27T23:00:00.000Z'
  
  test('date in russian format - 28.01.2019', () =&gt; {
        const russianDateFormat = 'DD.MM.YYYY'
        expect(getApiDateFormat('28.01.2019', russianDateFormat)).toEqual(
          formattedDate,
        )
      })
  </code></pre>
  
  <p>since I'm currently located in <code>Europe/Warsaw</code> timezone. How to make this test location independent?</p>
  
  <p>I've tried to use <code>jest.mock</code> to replace <code>moment</code> used by <code>getApiDateFormat</code> by <code>moment.tz.setDefault("America/New_York")</code>, however, all my attempts have failed since they have no influence on <code>moment</code> lib imported by <code>getApiDateFormat</code>.</p>
  
  <p>How to solve such a problem and test it properly?</p>