Skip to content

Commit

Permalink
fix: date prototype when using setSystemTime (#4584)
Browse files Browse the repository at this point in the history
  • Loading branch information
spiroka authored Nov 27, 2023
1 parent f377a3b commit 3f8c3fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/vitest/src/integrations/mock/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
6 changes: 6 additions & 0 deletions test/core/test/date-mock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

0 comments on commit 3f8c3fb

Please sign in to comment.