-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy-date.spec.ts
executable file
·39 lines (33 loc) · 1020 Bytes
/
proxy-date.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { mockDate, unmockDate } from './proxy-date'
import { describe, it, expect } from 'vitest'
const D = global.Date
describe('proxyDate', function () {
const date = '2019-01-19T00:20:20.654Z'
mockDate(date)
console.log(Date)
const mockedDate = Date.now()
it('should work for constructor', async () => {
expect(new Date().toISOString()).toEqual(date)
await new Promise((resolve) => {
setTimeout(() => {
expect(new Date().toISOString()).toEqual(date)
resolve(null)
}, 100)
})
})
it('should work for .now', async () => {
expect(Date.now()).toMatchInlineSnapshot(`1547857220654`)
await new Promise((resolve) => {
setTimeout(() => {
expect(Date.now()).toMatchInlineSnapshot(`1547857220654`)
resolve(null)
}, 100)
})
})
it('should unmockDate', async () => {
unmockDate()
expect(Date.now() > mockedDate)
expect(new Date().getTime() * 1 > mockedDate)
expect(global._unmockedDate).toBe(undefined)
})
})