From b7fdb54193c0bf34f4a50e9b58f9f17824e0e182 Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Mon, 21 Oct 2024 12:02:35 +0200 Subject: [PATCH] Fix constructor-based checks for fake Date no longer pass after installing --- src/fake-timers-src.js | 2 +- test/fake-timers-test.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/fake-timers-src.js b/src/fake-timers-src.js index f368628..5741f96 100644 --- a/src/fake-timers-src.js +++ b/src/fake-timers-src.js @@ -450,7 +450,7 @@ function withGlobal(_global) { // ensures identity checks using the constructor prop still works // this should have no other functional effect - this.constructor = Date; + this.constructor = NativeDate; } static [Symbol.hasInstance](instance) { diff --git a/test/fake-timers-test.js b/test/fake-timers-test.js index 38e08e0..ae3e8c6 100644 --- a/test/fake-timers-test.js +++ b/test/fake-timers-test.js @@ -3203,6 +3203,9 @@ describe("FakeTimers", function () { // issue #510 it("creates Date objects where the constructor prop matches the original", function () { const realDate = new Date(); + Date = NOOP; // eslint-disable-line no-global-assign + global.Date = NOOP; + const date = new this.clock.Date(); assert.equals(date.constructor.name, realDate.constructor.name);