Skip to content

Commit

Permalink
Add an error when creating a clock with no Date object (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisBrunner authored and fatso83 committed Sep 9, 2018
1 parent 5c39f53 commit 1278eaa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lolex-src.js
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions test/lolex-test.js
Expand Up @@ -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 () {
Expand Down

0 comments on commit 1278eaa

Please sign in to comment.