Skip to content

Commit 29f9547

Browse files
authored
Ensure checks based on the constructor property passes for fake Dates (#511)
1 parent ed43eb8 commit 29f9547

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/fake-timers-src.js

+4
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,10 @@ function withGlobal(_global) {
447447
} else {
448448
super(...arguments);
449449
}
450+
451+
// ensures identity checks using the constructor prop still works
452+
// this should have no other functional effect
453+
this.constructor = Date;
450454
}
451455

452456
static [Symbol.hasInstance](instance) {

test/fake-timers-test.js

+9
Original file line numberDiff line numberDiff line change
@@ -3200,6 +3200,15 @@ describe("FakeTimers", function () {
32003200
assert(date instanceof realDate.constructor);
32013201
});
32023202

3203+
// issue #510
3204+
it("creates Date objects where the constructor prop matches the original", function () {
3205+
const realDate = new Date();
3206+
const date = new this.clock.Date();
3207+
3208+
assert.equals(date.constructor.name, realDate.constructor.name);
3209+
assert.equals(date.constructor, realDate.constructor);
3210+
});
3211+
32033212
it("creates Date objects representing clock time", function () {
32043213
const date = new this.clock.Date();
32053214

0 commit comments

Comments
 (0)