Skip to content

Commit

Permalink
Add a guard to prevent test from failing in Puppeteer
Browse files Browse the repository at this point in the history
  • Loading branch information
fatso83 committed Aug 26, 2024
1 parent 13024b8 commit fab62df
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions test/fake-timers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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'/);
});
}
});

0 comments on commit fab62df

Please sign in to comment.