Skip to content

Commit 524f5b6

Browse files
committed
test(date): include separate tests for negative and positive offset time zones
Signed-off-by: Sector6759 <149817326+Sector6759@users.noreply.github.com>
1 parent 3d0d931 commit 524f5b6

1 file changed

Lines changed: 155 additions & 5 deletions

File tree

tests/date.test.ts

Lines changed: 155 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,38 @@ describe('date', () => {
8282
})
8383
})
8484

85-
describe('getDayNames', () => {
85+
describe('getDayNames TZ=Europe/Berlin', () => {
86+
beforeEach(() => {
87+
vi.stubEnv('TZ', 'Europe/Berlin')
88+
})
89+
afterEach(() => {
90+
vi.unstubAllEnvs()
91+
// @ts-expect-error - Mocking for tests
92+
delete globalThis.dayNames
93+
})
94+
95+
it('returns `globalThis.dayNames` when defined', () => {
96+
globalThis.dayNames = ['Day 0', 'Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5', 'Day 6']
97+
expect(getDayNames()).toEqual(globalThis.dayNames)
98+
})
99+
100+
it('returns English day names in "en-US" locale when `globalThis.dayNames` is not defined', () => {
101+
getCanonicalLocale.mockReturnValue('en-US')
102+
expect(getDayNames()).toEqual(['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'])
103+
})
104+
105+
it('returns German day names in "de-DE" locale when `globalThis.dayNames` is not defined', () => {
106+
getCanonicalLocale.mockReturnValue('de-DE')
107+
expect(getDayNames()).toEqual(['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'])
108+
})
109+
})
110+
111+
describe('getDayNames TZ=America/New_York', () => {
112+
beforeEach(() => {
113+
vi.stubEnv('TZ', 'America/New_York')
114+
})
86115
afterEach(() => {
116+
vi.unstubAllEnvs()
87117
// @ts-expect-error - Mocking for tests
88118
delete globalThis.dayNames
89119
})
@@ -104,8 +134,12 @@ describe('date', () => {
104134
})
105135
})
106136

107-
describe('getDayNamesShort', () => {
137+
describe('getDayNamesShort TZ=Europe/Berlin', () => {
138+
beforeEach(() => {
139+
vi.stubEnv('TZ', 'Europe/Berlin')
140+
})
108141
afterEach(() => {
142+
vi.unstubAllEnvs()
109143
// @ts-expect-error - Mocking for tests
110144
delete globalThis.dayNamesShort
111145
})
@@ -126,8 +160,38 @@ describe('date', () => {
126160
})
127161
})
128162

129-
describe('getDayNamesMin', () => {
163+
describe('getDayNamesShort TZ=America/New_York', () => {
164+
beforeEach(() => {
165+
vi.stubEnv('TZ', 'America/New_York')
166+
})
130167
afterEach(() => {
168+
vi.unstubAllEnvs()
169+
// @ts-expect-error - Mocking for tests
170+
delete globalThis.dayNamesShort
171+
})
172+
173+
it('returns `globalThis.dayNamesShort` when defined', () => {
174+
globalThis.dayNamesShort = ['D. 0', 'D. 1', 'D. 2', 'D. 3', 'D. 4', 'D. 5', 'D. 6']
175+
expect(getDayNamesShort()).toEqual(globalThis.dayNamesShort)
176+
})
177+
178+
it('returns English short day names from `Intl` in "en-US" locale when `globalThis.dayNamesShort` is not defined', () => {
179+
getCanonicalLocale.mockReturnValue('en-US')
180+
expect(getDayNamesShort()).toEqual(['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'])
181+
})
182+
183+
it('returns German short day names from `Intl` in "de-DE" locale when `globalThis.dayNamesShort` is not defined', () => {
184+
getCanonicalLocale.mockReturnValue('de-DE')
185+
expect(getDayNamesShort()).toEqual(['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'])
186+
})
187+
})
188+
189+
describe('getDayNamesMin TZ=Europe/Berlin', () => {
190+
beforeEach(() => {
191+
vi.stubEnv('TZ', 'Europe/Berlin')
192+
})
193+
afterEach(() => {
194+
vi.unstubAllEnvs()
131195
// @ts-expect-error - Mocking for tests
132196
delete globalThis.dayNamesMin
133197
})
@@ -148,8 +212,64 @@ describe('date', () => {
148212
})
149213
})
150214

151-
describe('getMonthNames', () => {
215+
describe('getDayNamesMin TZ=America/New_York', () => {
216+
beforeEach(() => {
217+
vi.stubEnv('TZ', 'America/New_York')
218+
})
152219
afterEach(() => {
220+
vi.unstubAllEnvs()
221+
// @ts-expect-error - Mocking for tests
222+
delete globalThis.dayNamesMin
223+
})
224+
225+
it('returns `globalThis.dayNamesMin` when defined', () => {
226+
globalThis.dayNamesMin = ['D0', 'D1', 'D2', 'D3', 'D4', 'D5', 'D6']
227+
expect(getDayNamesMin()).toEqual(globalThis.dayNamesMin)
228+
})
229+
230+
it('returns English narrow day names from `Intl` in "en-US" locale when `globalThis.dayNamesMin` is not defined', () => {
231+
getCanonicalLocale.mockReturnValue('en-US')
232+
expect(getDayNamesMin()).toEqual(['S', 'M', 'T', 'W', 'T', 'F', 'S'])
233+
})
234+
235+
it('returns German narrow day names from `Intl` in "de-DE" locale when `globalThis.dayNamesMin` is not defined', () => {
236+
getCanonicalLocale.mockReturnValue('de-DE')
237+
expect(getDayNamesMin()).toEqual(['S', 'M', 'D', 'M', 'D', 'F', 'S'])
238+
})
239+
})
240+
241+
describe('getMonthNames TZ=Europe/Berlin', () => {
242+
beforeEach(() => {
243+
vi.stubEnv('TZ', 'Europe/Berlin')
244+
})
245+
afterEach(() => {
246+
vi.unstubAllEnvs()
247+
// @ts-expect-error - Mocking for tests
248+
delete globalThis.monthNames
249+
})
250+
251+
it('returns `globalThis.monthNames` when defined', () => {
252+
globalThis.monthNames = ['Month 0', 'Month 1', 'Month 2', 'Month 3', 'Month 4', 'Month 5', 'Month 6', 'Month 7', 'Month 8', 'Month 9', 'Month 10', 'Month 11']
253+
expect(getMonthNames()).toEqual(globalThis.monthNames)
254+
})
255+
256+
it('returns English month names from `Intl` in "en-US" locale when `globalThis.monthNames` is not defined', () => {
257+
getCanonicalLocale.mockReturnValue('en-US')
258+
expect(getMonthNames()).toEqual(['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'])
259+
})
260+
261+
it('returns German month names from `Intl` in "de-DE" locale when `globalThis.monthNames` is not defined', () => {
262+
getCanonicalLocale.mockReturnValue('de-DE')
263+
expect(getMonthNames()).toEqual(['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'])
264+
})
265+
})
266+
267+
describe('getMonthNames TZ=America/New_York', () => {
268+
beforeEach(() => {
269+
vi.stubEnv('TZ', 'America/New_York')
270+
})
271+
afterEach(() => {
272+
vi.unstubAllEnvs()
153273
// @ts-expect-error - Mocking for tests
154274
delete globalThis.monthNames
155275
})
@@ -170,8 +290,38 @@ describe('date', () => {
170290
})
171291
})
172292

173-
describe('getMonthNamesShort', () => {
293+
describe('getMonthNamesShort TZ=Europe/Berlin', () => {
294+
beforeEach(() => {
295+
vi.stubEnv('TZ', 'Europe/Berlin')
296+
})
297+
afterEach(() => {
298+
vi.unstubAllEnvs()
299+
// @ts-expect-error - Mocking for tests
300+
delete globalThis.monthNamesShort
301+
})
302+
303+
it('returns `globalThis.monthNamesShort` when defined', () => {
304+
globalThis.monthNamesShort = ['M. 0', 'M. 1', 'M. 2', 'M. 3', 'M. 4', 'M. 5', 'M. 6', 'M. 7', 'M. 8', 'M. 9', 'M. 10', 'M. 11']
305+
expect(getMonthNamesShort()).toEqual(globalThis.monthNamesShort)
306+
})
307+
308+
it('returns English short month names from `Intl` in "en-US" locale when `globalThis.monthNamesShort` is not defined', () => {
309+
getCanonicalLocale.mockReturnValue('en-US')
310+
expect(getMonthNamesShort()).toEqual(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'])
311+
})
312+
313+
it('returns German short month names from `Intl` in "de-DE" locale when `globalThis.monthNamesShort` is not defined', () => {
314+
getCanonicalLocale.mockReturnValue('de-DE')
315+
expect(getMonthNamesShort()).toEqual(['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'])
316+
})
317+
})
318+
319+
describe('getMonthNamesShort TZ=America/New_York', () => {
320+
beforeEach(() => {
321+
vi.stubEnv('TZ', 'America/New_York')
322+
})
174323
afterEach(() => {
324+
vi.unstubAllEnvs()
175325
// @ts-expect-error - Mocking for tests
176326
delete globalThis.monthNamesShort
177327
})

0 commit comments

Comments
 (0)