forked from iamkun/dayjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cs.test.js
52 lines (47 loc) · 1.32 KB
/
cs.test.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
import moment from 'moment'
import MockDate from 'mockdate'
import dayjs from '../../src'
import relativeTime from '../../src/plugin/relativeTime'
import '../../src/locale/cs'
dayjs.extend(relativeTime)
beforeEach(() => {
MockDate.set(new Date())
})
afterEach(() => {
MockDate.reset()
})
it('RelativeTime: Time from X', () => {
const T = [
[44.4, 'second'], // a few seconds
[89.5, 'second'], // a minute
[2, 'minute'], // 2 minutes
[43, 'minute'], // 43 minutes
[45, 'minute'], // an hour
[3, 'hour'], // 3 hours
[21, 'hour'], // 21 hours
[1, 'day'], // a day
[3, 'day'], // 3 day
[25, 'day'], // 25 days
[1, 'month'], // a month
[2, 'month'], // 2 month
[10, 'month'], // 10 month
[1, 'year'], // a year
[2, 'year'], // 2 year
[5, 'year'], // 5 year
[18, 'month'] // 2 years
]
T.forEach((t) => {
dayjs.locale('cs')
moment.locale('cs')
const dayjsDay = dayjs()
const momentDay = moment()
const dayjsCompare = dayjs().add(t[0], t[1])
const momentCompare = moment().add(t[0], t[1])
expect(dayjsDay.from(dayjsCompare))
.toBe(momentDay.from(momentCompare))
expect(dayjsDay.to(dayjsCompare))
.toBe(momentDay.to(momentCompare))
expect(dayjsDay.from(dayjsCompare, true))
.toBe(momentDay.from(momentCompare, true))
})
})