Skip to content

Commit

Permalink
Ensure checks based Object.keys length pass for fake Dates
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderweiss committed Oct 28, 2024
1 parent 77a516c commit 074e939
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/fake-timers-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions test/fake-timers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 074e939

Please sign in to comment.