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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…