Skip to content

Commit 3f8c3fb

Browse files
authored
fix: date prototype when using setSystemTime (#4584)
1 parent f377a3b commit 3f8c3fb

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

packages/vitest/src/integrations/mock/date.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ class MockDate extends RealDate {
5555
break
5656
}
5757

58+
Object.setPrototypeOf(date, MockDate.prototype)
59+
5860
return date
5961
}
6062
}
6163

62-
// MockDate.prototype = RealDate.prototype
63-
6464
MockDate.UTC = RealDate.UTC
6565

6666
MockDate.now = function () {

test/core/test/date-mock.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,10 @@ describe('testing date mock functionality', () => {
3333

3434
expect(Date.now()).toBe(timeStrMs)
3535
})
36+
37+
test('date prototype is correct', () => {
38+
vi.setSystemTime(new Date(2000, 1, 1))
39+
40+
expect(new Date()).toBeInstanceOf(Date)
41+
})
3642
})

0 commit comments

Comments
 (0)