From fccb65cfabd86558f159541583543eb7c2889f11 Mon Sep 17 00:00:00 2001 From: Justin Hernandez Date: Thu, 8 Jan 2026 12:22:14 -0800 Subject: [PATCH] fix tests --- .../DocumentSelectorForProvingScreen.test.tsx | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/app/tests/src/screens/verification/DocumentSelectorForProvingScreen.test.tsx b/app/tests/src/screens/verification/DocumentSelectorForProvingScreen.test.tsx index 1f7006b33..d99cd3f9d 100644 --- a/app/tests/src/screens/verification/DocumentSelectorForProvingScreen.test.tsx +++ b/app/tests/src/screens/verification/DocumentSelectorForProvingScreen.test.tsx @@ -20,17 +20,27 @@ import { usePassport } from '@/providers/passportDataProvider'; import { DocumentSelectorForProvingScreen } from '@/screens/verification/DocumentSelectorForProvingScreen'; // Mock useFocusEffect to behave like useEffect in tests -// Note: We call the callback directly without requiring React to avoid OOM in CI +// Note: We use a closure-based approach to avoid requiring React (prevents OOM per test-memory-optimization rules) jest.mock('@react-navigation/native', () => { const actual = jest.requireActual('@react-navigation/native'); + + // Track execution per component instance using a Map + const executionMap = new Map(); + return { ...actual, - useFocusEffect: (callback: () => void) => { - // Call the callback immediately, simulating focus effect in tests - // We use setTimeout to defer execution similar to useEffect - setTimeout(() => { - callback(); - }, 0); + useFocusEffect: (callback: () => void | (() => void)) => { + // Use a stable object as key - in real usage, callback is stable due to useCallback + if (!executionMap.has(callback)) { + executionMap.set(callback, true); + // Schedule callback to run after current render (simulates focus effect) + Promise.resolve().then(() => { + const cleanup = callback(); + if (typeof cleanup === 'function') { + cleanup(); + } + }); + } }, }; });