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 localeMatch from './locale-match.js';
|
||||||
import mem from './mem';
|
import mem from './mem.js';
|
||||||
|
|
||||||
const locales = [...navigator.languages];
|
function initLocales() {
|
||||||
try {
|
const newLocales = [...navigator.languages];
|
||||||
const dtfLocale = new Intl.DateTimeFormat().resolvedOptions().locale;
|
try {
|
||||||
if (!locales.includes(dtfLocale)) {
|
const dtfLocale = new Intl.DateTimeFormat().resolvedOptions().locale;
|
||||||
locales.push(dtfLocale);
|
if (!newLocales.includes(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 {
|
||||||
|
|
|
@ -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
|
||||||
|
|
Ładowanie…
Reference in New Issue