Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3c483bf

Browse files
authored
fix(fake-timers): convert Date to milliseconds before passing to @sinonjs/fake-timers (#16029)
1 parent 7338963 commit 3c483bf

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
### Fixes
1111

1212
- `[expect-utils]` Fix `toStrictEqual` failing on `structuredClone` results due to cross-realm constructor mismatch ([#14011](https://github.com/jestjs/jest/issues/14011))
13+
- `[fake-timers)]` Convert `Date` to milliseconds before passing to `@sinonjs/fake-timers` ([#16029](https://github.com/jestjs/jest/pull/16029))
1314
- `[jest-runtime]` Improve CJS-from-ESM interop: `__esModule`/Babel default unwrap, broader named-export coverage, and shared CJS singleton across importers ([#16050](https://github.com/jestjs/jest/pull/16050))
1415
- `[jest-runtime]` Load `.js` files with ESM syntax but no `"type":"module"` marker as native ESM ([#16050](https://github.com/jestjs/jest/pull/16050))
1516
- `[jest-runtime]` Fix deadlocks and double-evaluation in concurrent ESM and wasm imports ([#16050](https://github.com/jestjs/jest/pull/16050))

packages/jest-fake-timers/src/__tests__/sinon-integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe('`@sinonjs/fake-timers` integration', () => {
128128
expect(mockInstall).toHaveBeenCalledWith({
129129
advanceTimeDelta: 40,
130130
loopLimit: 2000,
131-
now: new Date('1995-12-17'),
131+
now: new Date('1995-12-17').getTime(),
132132
shouldAdvanceTime: true,
133133
shouldClearNativeTimers: true,
134134
toFake: [

packages/jest-fake-timers/src/modernFakeTimers.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export default class FakeTimers {
151151

152152
setSystemTime(now?: number | Date): void {
153153
if (this._checkFakeTimers()) {
154-
this._clock.setSystemTime(now);
154+
this._clock.setSystemTime(now instanceof Date ? now.getTime() : now);
155155
}
156156
}
157157

@@ -226,7 +226,10 @@ export default class FakeTimers {
226226
return {
227227
advanceTimeDelta,
228228
loopLimit: fakeTimersConfig.timerLimit || 100_000,
229-
now: fakeTimersConfig.now ?? Date.now(),
229+
now:
230+
fakeTimersConfig.now instanceof Date
231+
? fakeTimersConfig.now.getTime()
232+
: (fakeTimersConfig.now ?? Date.now()),
230233
shouldAdvanceTime: Boolean(fakeTimersConfig.advanceTimers),
231234
shouldClearNativeTimers: true,
232235
toFake: [...toFake],

0 commit comments

Comments
 (0)