Skip to content

Instantly share code, notes, and snippets.

@lil12t
Last active January 13, 2021 17:23
Show Gist options
  • Save lil12t/cdb5039227217cf92bdfabbd3a05d0d1 to your computer and use it in GitHub Desktop.
Save lil12t/cdb5039227217cf92bdfabbd3a05d0d1 to your computer and use it in GitHub Desktop.
jest mock new Date()
/**
* 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