loading...

re: How to mock Date with Jest VIEW POST

FULL DISCUSSION
 

I just want to point out that both Date and RealDate reference the same object, so when you replace the function Date.now, it's also changing RealDate.now and your global.Date = RealDate at the end is not doing what you think it's doing.

What you should do if you want to keep and reassign the original now function is keep a reference to that function:

const realNow = Date.now

Date.now = () => 1000

Date.now = realNow
 

🙊Oh! You're completely right! Thank you so much, I will update my post!!! :)

(sorry for the late answer, I didn't saw the notification...)

code of conduct - report abuse