提交 05a72fda 编写于 作者: fxy060608's avatar fxy060608

chore: tests

上级 47c04de4
import { normalizeI18nLocale } from '../src/i18n' import { resolveI18nLocale } from '../src/i18n'
describe('normalizeI18nLocale', () => { describe('resolveI18nLocale', () => {
test('specifying locale', () => { test('specifying locale', () => {
expect(normalizeI18nLocale({ 'zh-Hans': {}, fr: {} }, 'fr')).toBe('fr') expect(resolveI18nLocale('app', ['zh-Hans', 'fr'], 'fr')).toBe('fr')
}) })
test('fallback en', () => { test('fallback en(app)', () => {
expect(normalizeI18nLocale({ 'zh-Hans': {}, en: {} }, 'fr')).toBe('en') expect(resolveI18nLocale('app', ['zh-Hans', 'en'], 'fr')).toBe('en')
})
test('fallback en(mp)', () => {
expect(resolveI18nLocale('mp-weixin', ['zh-Hans', 'en'], 'fr')).toBe(
'zh-Hans'
)
}) })
test('fallback zh-Hans', () => { test('fallback zh-Hans', () => {
expect(normalizeI18nLocale({ 'zh-Hans': {}, es: {} })).toBe('zh-Hans') expect(resolveI18nLocale('app', ['zh-Hans', 'es'])).toBe('zh-Hans')
}) })
test('fallback zh-Hant', () => { test('fallback zh-Hant', () => {
expect(normalizeI18nLocale({ 'zh-Hant': {}, es: {} })).toBe('zh-Hant') expect(resolveI18nLocale('app', ['zh-Hant', 'es'])).toBe('zh-Hant')
}) })
test('fallback first locale', () => { test('fallback first locale', () => {
expect(normalizeI18nLocale({ fr: {}, es: {} })).toBe('fr') expect(resolveI18nLocale('app', ['fr', 'es'])).toBe('fr')
}) })
}) })
...@@ -55,7 +55,7 @@ export function initLocales(dir: string, withMessages: boolean = true) { ...@@ -55,7 +55,7 @@ export function initLocales(dir: string, withMessages: boolean = true) {
}, {} as Record<string, Record<string, string>>) }, {} as Record<string, Record<string, string>>)
} }
function resolveI18nLocale( export function resolveI18nLocale(
platfrom: UniApp.PLATFORM, platfrom: UniApp.PLATFORM,
locales: string[], locales: string[],
locale?: string locale?: string
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册