Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Jest Mocking Moment to *always* be utc for tests
jest.mock('moment', () => {
const moment = require.requireActual('moment');
return moment.utc;
});
@th3fallen

This comment has been minimized.

Copy link

commented Mar 17, 2017

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

@duro

This comment has been minimized.

Copy link

commented Oct 25, 2017

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

@bbshih

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.