Skip to content

Commit

Permalink
Fix constructor-based checks for fake Date no longer pass after insta…
Browse files Browse the repository at this point in the history
…lling
  • Loading branch information
alexanderweiss committed Oct 21, 2024
1 parent 2eb02fe commit b7fdb54
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/fake-timers-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ function withGlobal(_global) {

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

static [Symbol.hasInstance](instance) {
Expand Down
3 changes: 3 additions & 0 deletions test/fake-timers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3203,6 +3203,9 @@ describe("FakeTimers", function () {
// issue #510
it("creates Date objects where the constructor prop matches the original", function () {
const realDate = new Date();
Date = NOOP; // eslint-disable-line no-global-assign
global.Date = NOOP;

const date = new this.clock.Date();

assert.equals(date.constructor.name, realDate.constructor.name);
Expand Down

0 comments on commit b7fdb54

Please sign in to comment.