From 074e939ab4fde7dc8c8ccb85efa74d5341ff6c4a Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Mon, 28 Oct 2024 10:26:14 +0100 Subject: [PATCH] Ensure checks based Object.keys length pass for fake Dates --- src/fake-timers-src.js | 5 ++++- test/fake-timers-test.js | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/fake-timers-src.js b/src/fake-timers-src.js index 5741f96..b9a8a8d 100644 --- a/src/fake-timers-src.js +++ b/src/fake-timers-src.js @@ -450,7 +450,10 @@ function withGlobal(_global) { // ensures identity checks using the constructor prop still works // this should have no other functional effect - this.constructor = NativeDate; + Object.defineProperty(this, "constructor", { + value: NativeDate, + enumerable: false, + }); } static [Symbol.hasInstance](instance) { diff --git a/test/fake-timers-test.js b/test/fake-timers-test.js index ae3e8c6..0a4b676 100644 --- a/test/fake-timers-test.js +++ b/test/fake-timers-test.js @@ -3212,6 +3212,12 @@ describe("FakeTimers", function () { assert.equals(date.constructor, realDate.constructor); }); + it("creates Date objects where the constructor prop is not enumerable", function () { + const date = new this.clock.Date(); + + assert.equals(Object.keys(date).length, 0); + }); + it("creates Date objects representing clock time", function () { const date = new this.clock.Date();