From ec847816c14264e43b24f60916b1c3441f518fe5 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 17 Sep 2024 10:06:48 -0500 Subject: [PATCH] Protect util handling, update test --- src/locale/helpers.ts | 3 ++- src/state/persisted/schema.ts | 2 +- src/state/session/__tests__/session-test.ts | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/locale/helpers.ts b/src/locale/helpers.ts index de84c98dd8..a7517eae9b 100644 --- a/src/locale/helpers.ts +++ b/src/locale/helpers.ts @@ -188,9 +188,10 @@ export function fixLegacyLanguageCode(code: string | null): string | null { * * If no match, returns `en`. */ -export function findSupportedAppLanguage(languageTags: string[]) { +export function findSupportedAppLanguage(languageTags: (string | undefined)[]) { const supported = new Set(Object.values(AppLanguage)) for (const tag of languageTags) { + if (!tag) continue if (supported.has(tag as AppLanguage)) { return tag } diff --git a/src/state/persisted/schema.ts b/src/state/persisted/schema.ts index 01c33c3c3e..8040179496 100644 --- a/src/state/persisted/schema.ts +++ b/src/state/persisted/schema.ts @@ -146,7 +146,7 @@ export const defaults: Schema = { .slice(0, 6), // try full language tag first, then fallback to language code appLanguage: findSupportedAppLanguage([ - deviceLocales[0].languageTag, + deviceLocales.at(0)?.languageTag, deviceLanguageCodes[0], ]), }, diff --git a/src/state/session/__tests__/session-test.ts b/src/state/session/__tests__/session-test.ts index 3e22c262cb..44c5cf9343 100644 --- a/src/state/session/__tests__/session-test.ts +++ b/src/state/session/__tests__/session-test.ts @@ -10,6 +10,10 @@ jest.mock('jwt-decode', () => ({ }, })) +jest.mock('expo-localization', () => ({ + getLocales: () => [], +})) + describe('session', () => { it('can log in and out', () => { let state = getInitialState([])