Skip to content

Instantly share code, notes, and snippets.

@lededje
Last active May 29, 2018 10:42
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lededje/44aeddf1dc2a5e6064e3b29dc35a7a2d to your computer and use it in GitHub Desktop.
Save lededje/44aeddf1dc2a5e6064e3b29dc35a7a2d to your computer and use it in GitHub Desktop.
Jest Mocking Moment to *always* be utc for tests
jest.mock('moment', () => {
const moment = require.requireActual('moment');
return moment.utc;
});
@th3fallen
Copy link

You ever done this with moment-timezone enabled as well?

@duro
Copy link

duro commented Oct 25, 2017

This does not work if you are using any static moment methods like moment.isMoment or moment.localeData

@bbshih
Copy link

bbshih commented Oct 25, 2017

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