-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.spec.ts
31 lines (26 loc) · 1.14 KB
/
index.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
import { describe, expect, it, vi } from 'vitest'
import { timestamp } from './index.ts'
describe('timestamp', () => {
it('should return a string in YYYYMMDDhhmmssSSS format by default', () => {
const result = timestamp()
expect(result).toMatch(/^\d{17}$/)
})
it('should return a string in YYYYMMDDhhmmss format when millisecond is excluded', () => {
const result = timestamp({ excludeMillisecond: true })
expect(result).toMatch(/^\d{14}$/)
})
it('should return a string in YYYYMMDD format when time is excluded', () => {
const result = timestamp({ excludeTime: true })
expect(result).toMatch(/^\d{8}$/)
})
it('should return the respect timestamp with a custom Date value', () => {
vi.setSystemTime('2050-03-04T12:03:04.123')
const result = timestamp(new Date(), { excludeMillisecond: true })
expect(result).toBe('20500304120304')
})
it('should return a timestamp with a custom separator', () => {
const separator = '-'
const result = timestamp({ separator })
expect(result).toMatch(new RegExp(['^\\d{4}', '\\d{2}', '\\d{2}', '\\d{2}', '\\d{2}', '\\d{2}', '\\d{3}$'].join(separator)))
})
})