Last active
May 29, 2018 10:42
-
-
Save lededje/44aeddf1dc2a5e6064e3b29dc35a7a2d to your computer and use it in GitHub Desktop.
Jest Mocking Moment to *always* be utc for tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jest.mock('moment', () => { | |
const moment = require.requireActual('moment'); | |
return moment.utc; | |
}); |
This does not work if you are using any static moment methods like moment.isMoment
or moment.localeData
Thanks for this. Per the 2 comments above, I got it working for static methods using moment-timezone:
https://gist.github.com/bbshih/1cac2e30e5884102a66a07fbe464b50c
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You ever done this with moment-timezone enabled as well?