Fix date-time-format test

pull/1244/head
Lim Chee Aun 2025-08-20 22:44:43 +08:00
rodzic d7f1807ceb
commit 5bf47bccd7
2 zmienionych plików z 25 dodań i 10 usunięć

Wyświetl plik

@ -1,13 +1,23 @@
import localeMatch from './locale-match'; import localeMatch from './locale-match.js';
import mem from './mem'; import mem from './mem.js';
const locales = [...navigator.languages]; function initLocales() {
const newLocales = [...navigator.languages];
try { try {
const dtfLocale = new Intl.DateTimeFormat().resolvedOptions().locale; const dtfLocale = new Intl.DateTimeFormat().resolvedOptions().locale;
if (!locales.includes(dtfLocale)) { if (!newLocales.includes(dtfLocale)) {
locales.push(dtfLocale); newLocales.push(dtfLocale);
} }
} catch {} } catch {}
return newLocales;
}
let locales = initLocales();
// For testing: refresh locales from current navigator state
export function refreshLocales() {
locales = initLocales();
}
const createLocale = mem((language, options = {}) => { const createLocale = mem((language, options = {}) => {
try { try {

Wyświetl plik

@ -1,6 +1,8 @@
// @ts-check // @ts-check
import { test, expect } from '@playwright/test'; import { test, expect } from '@playwright/test';
import DateTimeFormat from '../src/utils/date-time-format.js'; import DateTimeFormat, {
refreshLocales,
} from '../src/utils/date-time-format.js';
// Store original navigator properties for cleanup // Store original navigator properties for cleanup
let originalLanguage; let originalLanguage;
@ -22,6 +24,9 @@ const mockNavigator = (language, languages) => {
get: () => languages || [language], get: () => languages || [language],
configurable: true, configurable: true,
}); });
// Automatically refresh locales after mocking
refreshLocales();
}; };
// Reset navigator to original state // Reset navigator to original state