sf-time-mock
v1.0.2
Published
Mock utility for a function returning a timestamp (like Date.now()).
Downloads
197
Readme
sf-time-mock
Mock utility for a function returning a timestamp (like Date.now()).
Usage
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'
initTimeMock() ⇒ function
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
- ~timeStub() ⇒ Number
initTimeMock~timeStub() ⇒ Number
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
timeStub.setTime(value, n) ⇒ void
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. |
timeStub.reset() ⇒ void
Reset the time stub
Kind: static method of timeStub
timeStub.ended() ⇒ Boolean
Say if there is no more timestamp available
Kind: static method of timeStub
Returns: Boolean - A boolean indicating if it ended or not
timeStub.setTimes(theTimes) ⇒ void
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}). |
timeStub.appendTimes(theTimes) ⇒ void
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}). |