Skip to content

Commit

Permalink
Ensure checks based on the constructor property passes for fake Dates (
Browse files Browse the repository at this point in the history
  • Loading branch information
fatso83 authored Oct 17, 2024
1 parent ed43eb8 commit 29f9547
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/fake-timers-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ function withGlobal(_global) {
} else {
super(...arguments);
}

// ensures identity checks using the constructor prop still works
// this should have no other functional effect
this.constructor = Date;
}

static [Symbol.hasInstance](instance) {
Expand Down
9 changes: 9 additions & 0 deletions test/fake-timers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3200,6 +3200,15 @@ describe("FakeTimers", function () {
assert(date instanceof realDate.constructor);
});

// issue #510
it("creates Date objects where the constructor prop matches the original", function () {
const realDate = new Date();
const date = new this.clock.Date();

assert.equals(date.constructor.name, realDate.constructor.name);
assert.equals(date.constructor, realDate.constructor);
});

it("creates Date objects representing clock time", function () {
const date = new this.clock.Date();

Expand Down

0 comments on commit 29f9547

Please sign in to comment.