Mock utility for a function returning a timestamp (like Date.now()).
var initTimeMock = require('sf-time-mock');
// Init the time mock
var timeStub = initTimeMock();
// Set the current time
timeStub.setTime(1267833600000);
// Use it everywhere
new Date(timeStub()).toISOString();
// '2010-03-06T00:00:00.000Z'
Spawn a new time stub
Kind: global function
Returns: function
- A time stub
- initTimeMock() ⇒
function
- ~timeStub() ⇒
Number
- .setTime(value, n) ⇒
void
- .reset() ⇒
void
- .ended() ⇒
Boolean
- .setTimes(theTimes) ⇒
void
- .appendTimes(theTimes) ⇒
void
- .setTime(value, n) ⇒
- ~timeStub() ⇒
Return the next timestamp
Kind: inner method of initTimeMock
Returns: Number
- The next mocked timestamp
Throws:
YError
E_TIME_ENDED exception when no timestamp available
- ~timeStub() ⇒
Number
- .setTime(value, n) ⇒
void
- .reset() ⇒
void
- .ended() ⇒
Boolean
- .setTimes(theTimes) ⇒
void
- .appendTimes(theTimes) ⇒
void
- .setTime(value, n) ⇒
Set a timestamp for the n next calls
Kind: static method of timeStub
Param | Type | Description |
---|---|---|
value | Number |
The timestamp value |
n | Number |
The number of call it should be used. Default to Infinity. |
Reset the time stub
Kind: static method of timeStub
Say if there is no more timestamp available
Kind: static method of timeStub
Returns: Boolean
- A boolean indicating if it ended or not
Set a bunch of timestamp to the queue
Kind: static method of timeStub
Param | Type | Description |
---|---|---|
theTimes | Array |
An array of timestamps or timestamp objects (format: {value, n}). |
Add a bunch of timestamps to the queue
Kind: static method of timeStub
Param | Type | Description |
---|---|---|
theTimes | Array |
An array of timestamps or timestamp objects (format: {value, n}). |