Skip to content

Commit 754d785

Browse files
Ensure checks based Object.keys length pass for fake Dates (#513)
1 parent 77a516c commit 754d785

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/fake-timers-src.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,10 @@ function withGlobal(_global) {
450450

451451
// ensures identity checks using the constructor prop still works
452452
// this should have no other functional effect
453-
this.constructor = NativeDate;
453+
Object.defineProperty(this, "constructor", {
454+
value: NativeDate,
455+
enumerable: false,
456+
});
454457
}
455458

456459
static [Symbol.hasInstance](instance) {

test/fake-timers-test.js

+6
Original file line numberDiff line numberDiff line change
@@ -3212,6 +3212,12 @@ describe("FakeTimers", function () {
32123212
assert.equals(date.constructor, realDate.constructor);
32133213
});
32143214

3215+
it("creates Date objects where the constructor prop is not enumerable", function () {
3216+
const date = new this.clock.Date();
3217+
3218+
assert.equals(Object.keys(date).length, 0);
3219+
});
3220+
32153221
it("creates Date objects representing clock time", function () {
32163222
const date = new this.clock.Date();
32173223

0 commit comments

Comments
 (0)