From 5bd7dff2bcd66db97bbc6b36a20a9ddb4f411b23 Mon Sep 17 00:00:00 2001 From: Clark Tomlinson Date: Thu, 15 Dec 2016 16:14:02 -0500 Subject: [PATCH] Allow install to be called with date object --- src/lolex-src.js | 9 +++++++-- test/lolex-test.js | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lolex-src.js b/src/lolex-src.js index 93c0a51a..f8ac1778 100644 --- a/src/lolex-src.js +++ b/src/lolex-src.js @@ -610,8 +610,13 @@ function createClock(now, loopLimit) { exports.createClock = createClock; exports.install = function install(target, now, toFake, loopLimit) { - var i, - l; + var i, l; + + if (target instanceof Date) { + toFake = now; + now = target.getTime(); + target = null; + } if (typeof target === "number") { toFake = now; diff --git a/test/lolex-test.js b/test/lolex-test.js index 2fe03d55..11aa4071 100644 --- a/test/lolex-test.js +++ b/test/lolex-test.js @@ -41,6 +41,14 @@ describe("issue #59", function () { }); }); +describe('issue #73', function() { + it('should install with date object', function () { + var date = new Date('2015-09-25'); + var clock = lolex.install(date); + assert.same(date.clock, clock); + }); +}); + describe("lolex", function () { describe("setTimeout", function () {