Set moment timezone in Jest tests

This worked for me

 "scripts": {
   "test": "TZ=UTC jest",
   "coverage": "TZ=UTC jest --coverage"
 }

but ensure "moment-timezone": "^0.5.27" is installed in your npm dependencies


If you wish to set that timezone for all test files, setting the TZ environment should be enough but if you're looking for setting the timezone for a single test file, the following should be enough

import moment from 'moment-timezone'
moment.tz.setDefault('America/New_York')

https://momentjs.com/timezone/docs/#/using-timezones/default-timezone/


Use TZ env var...

You can prepend to your package.json so all machines run with the same timezone like so:

  "scripts": {
    "test": "TZ=UTC jest",
    "coverage": "TZ=UTC jest --coverage"
  },