Skip to content

Commit

Permalink
Fix toString() output
Browse files Browse the repository at this point in the history
The output when just inheriting was
function() { [native code] }
vs
function Date() { [native code] }
in the real Date object.

I had to make a choice between having the same function identity and function output and opted for the latter,
since that is what the mother sinon project targets.
  • Loading branch information
fatso83 committed Aug 26, 2024
1 parent 97d9312 commit 030e53c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/fake-timers-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@ function withGlobal(_global) {
};
}

ClockDate.toString = function toString() {
return NativeDate.toString();
};

// noinspection UnnecessaryLocalVariableJS
/**
* A normal Class constructor cannot be called without `new`, but Date can, so we need
Expand Down
4 changes: 2 additions & 2 deletions test/fake-timers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3358,8 +3358,8 @@ describe("FakeTimers", function () {
});
});

it("mirrors toString", function () {
assert.same(this.clock.Date.toString, Date.toString);
it("mirrors toString output", function () {
assert.same(this.clock.Date.toString(), Date.toString());
});
});

Expand Down

0 comments on commit 030e53c

Please sign in to comment.