DEV Community

Feralamillo
Feralamillo

Posted on

 

Mocking date.now() with jest.

Mocking Date.now() in a jest unit test.

jest
 .spyOn(global.Date, 'now')
 .mockImplementationOnce(() =>
    new Date('2010-10-10T10:10:10.100Z').valueOf()
  );

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.