Skip to content

Commit

Permalink
Refactor: rename single argument to be more descriptive
Browse files Browse the repository at this point in the history
  • Loading branch information
mroderick committed Oct 21, 2018
1 parent 24e09a9 commit 667afb2
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/sinon/util/fake_timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ function createClock(config) {
}

/**
* @param {number|Date|Object} args The unix epoch value to install with (default 0)
* @param {number|Date|Object} dateOrConfig The unix epoch value to install with (default 0)
* @returns {Object} Returns a lolex clock instance
*/
exports.useFakeTimers = function(args) {
var hasArguments = typeof args !== "undefined";
var argumentIsDateLike = (typeof args === "number" || args instanceof Date) && arguments.length === 1;
var argumentIsObject = args !== null && typeof args === "object" && arguments.length === 1;
exports.useFakeTimers = function(dateOrConfig) {
var hasArguments = typeof dateOrConfig !== "undefined";
var argumentIsDateLike =
(typeof dateOrConfig === "number" || dateOrConfig instanceof Date) && arguments.length === 1;
var argumentIsObject = dateOrConfig !== null && typeof dateOrConfig === "object" && arguments.length === 1;

if (!hasArguments) {
return createClock({
Expand All @@ -26,12 +27,12 @@ exports.useFakeTimers = function(args) {

if (argumentIsDateLike) {
return createClock({
now: args
now: dateOrConfig
});
}

if (argumentIsObject) {
return createClock(extend({}, args));
return createClock(extend({}, dateOrConfig));
}

throw new TypeError("useFakeTimers expected epoch or config object. See https://github.com/sinonjs/sinon");
Expand Down

0 comments on commit 667afb2

Please sign in to comment.