diff --git a/packages/vitest/src/integrations/mock/date.ts b/packages/vitest/src/integrations/mock/date.ts index e1027caaf1bf..6fe1b11b5c11 100644 --- a/packages/vitest/src/integrations/mock/date.ts +++ b/packages/vitest/src/integrations/mock/date.ts @@ -55,12 +55,12 @@ class MockDate extends RealDate { break } + Object.setPrototypeOf(date, MockDate.prototype) + return date } } -// MockDate.prototype = RealDate.prototype - MockDate.UTC = RealDate.UTC MockDate.now = function () { diff --git a/test/core/test/date-mock.test.ts b/test/core/test/date-mock.test.ts index eb0fb17b8915..39b98c9b35f2 100644 --- a/test/core/test/date-mock.test.ts +++ b/test/core/test/date-mock.test.ts @@ -33,4 +33,10 @@ describe('testing date mock functionality', () => { expect(Date.now()).toBe(timeStrMs) }) + + test('date prototype is correct', () => { + vi.setSystemTime(new Date(2000, 1, 1)) + + expect(new Date()).toBeInstanceOf(Date) + }) })