1.0.2 • Published 9 years ago

sf-time-mock v1.0.2

Weekly downloads
68
License
MIT
Repository
github
Last release
9 years ago

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

ParamTypeDescription
valueNumberThe timestamp value
nNumberThe 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

ParamTypeDescription
theTimesArrayAn 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

ParamTypeDescription
theTimesArrayAn array of timestamps or timestamp objects (format: {value, n}).
1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago