From 2902380b82a593a132fc5d41232ef015d144c69e Mon Sep 17 00:00:00 2001 From: situchan Date: Thu, 13 Aug 2026 18:28:14 +0600 Subject: [PATCH] fix flaky test --- tests/unit/SignInBackButtonTest.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/unit/SignInBackButtonTest.tsx b/tests/unit/SignInBackButtonTest.tsx index 338c94552496..f0c565946cf3 100644 --- a/tests/unit/SignInBackButtonTest.tsx +++ b/tests/unit/SignInBackButtonTest.tsx @@ -1,5 +1,7 @@ import {render} from '@testing-library/react-native'; +import type * as AppActions from '@libs/actions/App'; + import SignInModal from '@pages/signin/SignInModal'; import type {SignInPageRef} from '@pages/signin/SignInPage'; import {SignInPage} from '@pages/signin/SignInPage'; @@ -16,6 +18,9 @@ jest.mock('@libs/Navigation/Navigation', () => ({ goBack: () => { mockGoBack(); }, + dismissModal: jest.fn(), + navigate: jest.fn(), + isNavigationReady: () => Promise.resolve(), }, navigationRef: { get current() { @@ -24,6 +29,14 @@ jest.mock('@libs/Navigation/Navigation', () => ({ }, })); +// SignInModal fires a real OpenApp request on mount. The global fetch mock in jest/setup.ts resolves it, +// so `finallyData` merges IS_LOADING_APP: false, which re-runs the effect that dismisses the modal while +// the test is still running. Stubbing openApp keeps that async work out of this unit test. +jest.mock('@libs/actions/App', () => ({ + ...jest.requireActual('@libs/actions/App'), + openApp: jest.fn(), +})); + // Record the callbacks handed to the hook so the test can replay them. Jest resolves the platform-neutral // no-op variant, so the callbacks are never invoked for real here. const mockUseAndroidBackButtonHandler = jest.fn((callback: () => boolean) => callback);