From fab62dfa82e35425ae82952b7a6d3b234005f7a4 Mon Sep 17 00:00:00 2001 From: Carl-Erik Kopseng Date: Mon, 26 Aug 2024 11:40:44 +0200 Subject: [PATCH] Add a guard to prevent test from failing in Puppeteer --- test/fake-timers-test.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/test/fake-timers-test.js b/test/fake-timers-test.js index 8d130df..16019b2 100644 --- a/test/fake-timers-test.js +++ b/test/fake-timers-test.js @@ -26,6 +26,14 @@ let timersModule, timersPromisesModule; /* eslint-disable no-underscore-dangle */ globalObject.__runs = globalObject.__runs || 0; +let environmentSupportsCallingBuiltInsOnAlternativeThis = true; +try { + setTimeout.call({}, NOOP, 0); +} catch { + // Google Puppeteer will throw "Illegal invocation" + environmentSupportsCallingBuiltInsOnAlternativeThis = false; +} + const isRunningInWatchMode = ++globalObject.__runs > 1; /* eslint-enable no-underscore-dangle */ @@ -6076,11 +6084,13 @@ describe("missing timers", function () { }); }); - 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'/); - }); + if (environmentSupportsCallingBuiltInsOnAlternativeThis) { + it("should throw on trying to install 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'/); + }); + } });