From 1278eaade7da311d203fc6c33f67f85c828a09f2 Mon Sep 17 00:00:00 2001 From: Louis Brunner Date: Sun, 9 Sep 2018 08:35:01 +0100 Subject: [PATCH] Add an error when creating a clock with no Date object (#205) --- src/lolex-src.js | 5 +++++ test/lolex-test.js | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/lolex-src.js b/src/lolex-src.js index a4bbc054..14f55ca4 100644 --- a/src/lolex-src.js +++ b/src/lolex-src.js @@ -512,6 +512,11 @@ function withGlobal(_global) { start = start || 0; loopLimit = loopLimit || 1000; + if (NativeDate === undefined) { + throw new Error("The global scope doesn't have a `Date` object" + + " (see https://github.com/sinonjs/sinon/issues/1852#issuecomment-419622780)"); + } + var clock = { now: getEpoch(start), hrNow: 0, diff --git a/test/lolex-test.js b/test/lolex-test.js index cc229344..66848700 100644 --- a/test/lolex-test.js +++ b/test/lolex-test.js @@ -103,6 +103,17 @@ describe("issue #67", function () { }); }); +describe("issue sinon#1852", function () { + it("throws when creating a clock and global has no Date", function () { + var clock = lolex.withGlobal({ + setTimeout: function () {}, + clearTimeout: function () {} + }); + assert.exception(function () { clock.createClock(); }); + assert.exception(function () { clock.install(); }); + }); +}); + describe("lolex", function () { describe("setTimeout", function () {