deno.land / x / dayjs@v1.11.5 / test / locale.test.js

locale.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import MockDate from 'mockdate'import moment from 'moment'import dayjs from '../src'import es from '../src/locale/es'
beforeEach(() => { MockDate.set(new Date())})
afterEach(() => { MockDate.reset()})
const format = 'dddd D, MMMM'const NOT_SUPPORTED_LOCALE_STRING = 'not_supported_locale_string'
it('Uses spanish locale through constructor', () => { // not recommend expect(dayjs('2018-4-28', { locale: es }) .format(format)) .toBe('sábado 28, abril')})
it('set locale for one instance only', () => { expect(dayjs('2018-4-28') .format(format)) .toBe('Saturday 28, April')
expect(dayjs('2018-4-28') .locale(es).format(format)) .toBe('sábado 28, abril')
expect(dayjs('2018-4-28') .format(format)) .toBe('Saturday 28, April')})
it('set global locale', () => { dayjs.locale('en') expect(dayjs('2018-4-28').format(format)) .toBe('Saturday 28, April') dayjs.locale(es) expect(dayjs('2018-4-28').format(format)) .toBe('sábado 28, abril') dayjs.locale('en') expect(dayjs('2018-4-28').format(format)) .toBe('Saturday 28, April')})
it('get instance locale name', () => { expect(dayjs().locale()).toBe('en') expect(dayjs().locale()).toBe(moment().locale()) expect(dayjs().locale('es').locale()).toBe('es') expect(dayjs().locale('es').locale()).toBe(moment().locale('es').locale()) dayjs.locale(es) moment.locale('es') expect(dayjs().locale()).toBe('es') expect(dayjs().locale()).toBe(moment().locale())})
it('immutable instance locale', () => { dayjs.locale('en') const origin = dayjs('2018-4-28') expect(origin.format(format)) .toBe('Saturday 28, April') expect(origin.locale('es').format(format)) .toBe('sábado 28, abril') const changed = origin.locale('es') expect(changed.format(format)) .toBe('sábado 28, abril') expect(origin.format(format)) .toBe('Saturday 28, April')})
it('User custom locale', () => { expect(dayjs('2018-4-28') .locale('xx', { weekdays: Array(7).fill('week'), months: Array(12).fill('month') }) .format(format)) .toBe('week 28, month')})
describe('Instance locale inheritance', () => { const esDayjs = dayjs('2018-4-28').locale(es)
it('Clone', () => { expect(esDayjs.clone().format(format)) .toBe('sábado 28, abril') expect(dayjs(esDayjs).format(format)) .toBe('sábado 28, abril') })
it('StartOf EndOf', () => { expect(esDayjs.startOf('year').format(format)) .toBe('lunes 1, enero') expect(esDayjs.endOf('day').format(format)) .toBe('sábado 28, abril') })
it('Set', () => { expect(esDayjs.set('year', 2017).format(format)) .toBe('viernes 28, abril') })
it('Add', () => { expect(esDayjs.add(1, 'year').format(format)) .toBe('domingo 28, abril') expect(esDayjs.add(1, 'month').format(format)) .toBe('lunes 28, mayo') expect(esDayjs.add(1, 'minute').format(format)) .toBe('sábado 28, abril') })
it('dayjs.locale() returns locale name', () => { dayjs.locale(es) moment.locale('es') expect(dayjs.locale()).toBe(moment.locale())
dayjs.locale('en') moment.locale('en') expect(dayjs.locale()).toBe(moment.locale()) })})

it('Not supported locale string fallback to previous one (instance)', () => { const D = dayjs() expect(D.locale()).toBe('en') const D2 = D.locale(NOT_SUPPORTED_LOCALE_STRING) expect(D2.locale()).toBe('en') expect(D2.format()).toBe(D.format()) const D3 = D2.locale('es') expect(D3.locale()).toBe('es') const D4 = D3.locale(NOT_SUPPORTED_LOCALE_STRING) expect(D4.locale()).toBe('es')})
it('Not supported locale string fallback to previous one (global)', () => { expect(dayjs().locale()).toBe('en') dayjs.locale(NOT_SUPPORTED_LOCALE_STRING) expect(dayjs().locale()).toBe('en') dayjs.locale('es') expect(dayjs().locale()).toBe('es') dayjs.locale(NOT_SUPPORTED_LOCALE_STRING) expect(dayjs().locale()).toBe('es')})
dayjs

Version Info

Tagged at
a year ago