Last active
February 16, 2022 10:42
-
-
Save MikelArnaiz/eb569803073db5cf75cad2548395ade8 to your computer and use it in GitHub Desktop.
Mock Date in jest
This file contains hidden or 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
// 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