From 13024b8fb6acd2826eda5428fd3ebf537174e2c1 Mon Sep 17 00:00:00 2001 From: Carl-Erik Kopseng Date: Mon, 26 Aug 2024 11:18:49 +0200 Subject: [PATCH] Add a missing test on using timers not present on a custom global This was present in Sinon and should be here as well --- src/fake-timers-src.js | 5 ++++- test/fake-timers-test.js | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/fake-timers-src.js b/src/fake-timers-src.js index 94d2b4f..b2f7e8d 100644 --- a/src/fake-timers-src.js +++ b/src/fake-timers-src.js @@ -1057,6 +1057,9 @@ function withGlobal(_global) { if (isPresent.setImmediate) { timers.setImmediate = _global.setImmediate; + } + + if (isPresent.clearImmediate) { timers.clearImmediate = _global.clearImmediate; } @@ -1077,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 321a9d4..8d130df 100644 --- a/test/fake-timers-test.js +++ b/test/fake-timers-test.js @@ -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'/); + }); });