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

Wyświetl plik

@ -1,6 +1,8 @@
// @ts-check
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
let originalLanguage;
@ -22,6 +24,9 @@ const mockNavigator = (language, languages) => {
get: () => languages || [language],
configurable: true,
});
// Automatically refresh locales after mocking
refreshLocales();
};
// Reset navigator to original state