diff --git a/lolex.js b/lolex.js index 21430579..d7a110ca 100644 --- a/lolex.js +++ b/lolex.js @@ -612,8 +612,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 11aa4071..4b2d2b23 100644 --- a/test/lolex-test.js +++ b/test/lolex-test.js @@ -45,7 +45,8 @@ 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); + assert.same(clock.now, 1443139200000); + clock.uninstall(); }); }); @@ -1716,12 +1717,6 @@ describe("lolex", function () { assert.same(setInterval, lolex.timers.setInterval); assert.same(clearInterval, lolex.timers.clearInterval); }); - - it("does not be able to use date object for now", function () { - assert.exception(function () { - lolex.install(new Date(2011, 9, 1)); - }); - }); }); if (hrtimePresent) {