Skip to content

Instantly share code, notes, and snippets.

@MikelArnaiz
Last active February 16, 2022 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikelArnaiz/eb569803073db5cf75cad2548395ade8 to your computer and use it in GitHub Desktop.
Save MikelArnaiz/eb569803073db5cf75cad2548395ade8 to your computer and use it in GitHub Desktop.
Mock Date in jest
// https://github.com/facebook/jest/issues/2234#issuecomment-731451275
beforeAll(() => {
jest.useFakeTimers('modern'); // tell Jest to use a different timer implementation.
jest.setSystemTime(new Date('2022-02-15T22:30:00.000+01:00').getTime());
});
afterAll(() => {
// Back to reality...
jest.useRealTimers();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment