提交 | 用户 | age
|
2a61f6
|
1 |
import { parseTime } from '@/utils/index.js' |
L |
2 |
|
|
3 |
describe('Utils:parseTime', () => { |
|
4 |
const d = new Date('2018-07-13 17:54:01') // "2018-07-13 17:54:01" |
|
5 |
it('timestamp', () => { |
|
6 |
expect(parseTime(d)).toBe('2018-07-13 17:54:01') |
|
7 |
}) |
|
8 |
it('timestamp string', () => { |
|
9 |
expect(parseTime((d + ''))).toBe('2018-07-13 17:54:01') |
|
10 |
}) |
|
11 |
it('ten digits timestamp', () => { |
|
12 |
expect(parseTime((d / 1000).toFixed(0))).toBe('2018-07-13 17:54:01') |
|
13 |
}) |
|
14 |
it('new Date', () => { |
|
15 |
expect(parseTime(new Date(d))).toBe('2018-07-13 17:54:01') |
|
16 |
}) |
|
17 |
it('format', () => { |
|
18 |
expect(parseTime(d, '{y}-{m}-{d} {h}:{i}')).toBe('2018-07-13 17:54') |
|
19 |
expect(parseTime(d, '{y}-{m}-{d}')).toBe('2018-07-13') |
|
20 |
expect(parseTime(d, '{y}/{m}/{d} {h}-{i}')).toBe('2018/07/13 17-54') |
|
21 |
}) |
|
22 |
it('get the day of the week', () => { |
|
23 |
expect(parseTime(d, '{a}')).toBe('五') // 星期五 |
|
24 |
}) |
|
25 |
it('get the day of the week', () => { |
|
26 |
expect(parseTime(+d + 1000 * 60 * 60 * 24 * 2, '{a}')).toBe('日') // 星期日 |
|
27 |
}) |
|
28 |
it('empty argument', () => { |
|
29 |
expect(parseTime()).toBeNull() |
|
30 |
}) |
|
31 |
|
|
32 |
it('null', () => { |
|
33 |
expect(parseTime(null)).toBeNull() |
|
34 |
}) |
|
35 |
}) |