diff --git a/src/fake-timers-src.js b/src/fake-timers-src.js index c389223..b2f7e8d 100644 --- a/src/fake-timers-src.js +++ b/src/fake-timers-src.js @@ -456,6 +456,10 @@ function withGlobal(_global) { }; } + ClockDate.toString = function toString() { + return NativeDate.toString(); + }; + // noinspection UnnecessaryLocalVariableJS /** * A normal Class constructor cannot be called without `new`, but Date can, so we need @@ -1053,6 +1057,9 @@ function withGlobal(_global) { if (isPresent.setImmediate) { timers.setImmediate = _global.setImmediate; + } + + if (isPresent.clearImmediate) { timers.clearImmediate = _global.clearImmediate; } @@ -1073,7 +1080,7 @@ function withGlobal(_global) { } if (isPresent.queueMicrotask) { - timers.queueMicrotask = true; + timers.queueMicrotask = _global.queueMicrotask; } if (isPresent.cancelAnimationFrame) { diff --git a/test/fake-timers-test.js b/test/fake-timers-test.js index c876ab7..8d130df 100644 --- a/test/fake-timers-test.js +++ b/test/fake-timers-test.js @@ -3358,8 +3358,8 @@ describe("FakeTimers", function () { }); }); - it("mirrors toString", function () { - assert.same(this.clock.Date.toString, Date.toString); + it("mirrors toString output", function () { + assert.same(this.clock.Date.toString(), Date.toString()); }); }); @@ -6069,12 +6069,18 @@ describe("missing timers", function () { }); it(`should ignore timers in toFake that are not present in "global" when passed the ignore flag: [${timer}]`, function () { - //refute.exception(function () { FakeTimers.withGlobal({ Date }).install({ ignoreMissingTimers: true, toFake: [timer], }); - //}); }); }); + + it("should throw on trying to use standard timers that are not present on the custom global", function () { + assert.exception(function () { + FakeTimers.withGlobal({ setTimeout, Date }).install({ + toFake: ["setInterval"], + }); + }, /cannot be faked: 'setInterval'/); + }); });