-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathlocale.test.ts
More file actions
32 lines (28 loc) · 907 Bytes
/
locale.test.ts
File metadata and controls
32 lines (28 loc) · 907 Bytes
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
import { describe, expect, it } from 'vitest'
import {
formatDateTime,
getNavigatorLocales,
resolveDateTimeLocale,
} from '../locale'
describe('locale helpers', () => {
it('uses the first valid locale from navigator languages', () => {
expect(resolveDateTimeLocale(['undefined', 'en-GB', 'fr-FR'])).toBe('en-GB')
})
it('falls back to en-US when no provided locale is valid', () => {
expect(resolveDateTimeLocale(['undefined', 'en_US', null])).toBe('en-US')
})
it(
'formats dates without throwing when navigator.language is invalid',
{ timeout: 20_000 },
() => {
const submittedAt = new Date('2026-03-28T12:34:56.000Z')
const locales = getNavigatorLocales({
language: 'undefined',
languages: ['undefined'],
})
expect(formatDateTime(submittedAt, locales)).toBe(
submittedAt.toLocaleString('en-US'),
)
},
)
})