sf-time-mock

1.0.2 • Public • Published

sf-time-mock

Mock utility for a function returning a timestamp (like Date.now()).

NPM version Build status Dependency Status devDependency Status Coverage Status Code Climate

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~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.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}).

Package Sidebar

Install

npm i sf-time-mock

Weekly Downloads

22

Version

1.0.2

License

MIT

Last publish

Collaborators

  • arnaudspanneut
  • gplancke
  • nfroidure
  • sebastienelet
  • xavhan