Last active
January 13, 2021 17:23
-
-
Save lil12t/cdb5039227217cf92bdfabbd3a05d0d1 to your computer and use it in GitHub Desktop.
jest mock new Date()
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
/** | |
* Mocks new Date() in jest | |
*/ | |
const mockDate: any = new Date(1466424490000); | |
const spy = jest.spyOn(global, 'Date').mockImplementation(() => mockDate); | |
expect(YourTestResult.date).toEqual(new Date(1466424490000)); | |
spy.mockRestore(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment