kopia lustrzana https://github.com/cheeaun/phanpy
Fix date-time-format test
rodzic
d7f1807ceb
commit
5bf47bccd7
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Ładowanie…
Reference in New Issue