How to fake time in javascript?

sinon.useFakeTimers accepts a timestamp (integer) as parameter, not a Date object.

Try with

clock = sinon.useFakeTimers(new Date(2011,9,1).getTime());
new Date(); //=> return the fake Date 'Sat Oct 01 2011 00:00:00'

clock.restore();
new Date(); //=> will return the real time again (now)

If you use anything like setTimeout, make sure you read the docs because the useFakeTimers will disrupt the expected behavior of that code.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)