Skip to content

Commit 0f68716

Browse files
committed
fix: Jest manual mock for Navigation
1 parent 22a0136 commit 0f68716

12 files changed

Lines changed: 31 additions & 65 deletions
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Jest manual mock for Navigation.
3+
*
4+
* Used automatically when a test calls `jest.mock('@libs/Navigation/Navigation')` without a factory.
5+
* Tests that need custom behavior can still pass a factory to override specific methods.
6+
*/
7+
export default {
8+
navigate: jest.fn(),
9+
goBack: jest.fn(),
10+
getActiveRoute: jest.fn(() => ''),
11+
getActiveRouteWithoutParams: jest.fn(() => ''),
12+
getReportRHPActiveRoute: jest.fn(() => ''),
13+
isNavigationReady: jest.fn(() => Promise.resolve()),
14+
dismissModal: jest.fn(),
15+
dismissModalWithReport: jest.fn(),
16+
setNavigationActionToMicrotaskQueue: jest.fn((callback: () => void) => callback?.()),
17+
setParams: jest.fn(),
18+
clearPreloadedRoutes: jest.fn(),
19+
isTopmostRouteModalScreen: jest.fn(() => false),
20+
};

tests/ui/CategoryListItemHeaderTest.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
1515
import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct';
1616

1717
jest.mock('@components/ConfirmedRoute.tsx');
18-
jest.mock('@libs/Navigation/Navigation', () => ({
19-
getActiveRouteWithoutParams: jest.fn(() => ''),
20-
isNavigationReady: jest.fn(() => Promise.resolve()),
21-
navigate: jest.fn(),
22-
getActiveRoute: jest.fn(() => ''),
23-
}));
18+
jest.mock('@libs/Navigation/Navigation');
2419

2520
// Mock useResponsiveLayout to control screen size in tests
2621
jest.mock('@hooks/useResponsiveLayout', () => jest.fn());

tests/ui/DateFilterBaseResetTest.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ import CONST from '@src/CONST';
1010
import ONYXKEYS from '@src/ONYXKEYS';
1111

1212
jest.mock('@components/ConfirmedRoute.tsx');
13-
jest.mock('@libs/Navigation/Navigation', () => ({
14-
getActiveRouteWithoutParams: jest.fn(() => ''),
15-
isNavigationReady: jest.fn(() => Promise.resolve()),
16-
navigate: jest.fn(),
17-
getActiveRoute: jest.fn(() => ''),
18-
}));
13+
jest.mock('@libs/Navigation/Navigation');
1914

2015
const defaultDateValues: SearchDateValues = {
2116
[CONST.SEARCH.DATE_MODIFIERS.ON]: '2025-01-15',

tests/ui/DebugReportActionsTest.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ jest.mock('@react-navigation/native', () => {
2121
};
2222
});
2323

24-
jest.mock('@src/libs/Navigation/Navigation', () => ({
25-
navigate: jest.fn(),
26-
getActiveRouteWithoutParams: jest.fn(() => ''),
27-
isNavigationReady: jest.fn(() => Promise.resolve()),
28-
}));
24+
jest.mock('@src/libs/Navigation/Navigation');
2925

3026
describe('DebugReportActions', () => {
3127
beforeAll(() => {

tests/ui/MerchantListItemHeaderTest.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
1515
import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct';
1616

1717
jest.mock('@components/ConfirmedRoute.tsx');
18-
jest.mock('@libs/Navigation/Navigation', () => ({
19-
getActiveRouteWithoutParams: jest.fn(() => ''),
20-
isNavigationReady: jest.fn(() => Promise.resolve()),
21-
navigate: jest.fn(),
22-
getActiveRoute: jest.fn(() => ''),
23-
}));
18+
jest.mock('@libs/Navigation/Navigation');
2419

2520
// Mock useResponsiveLayout to control screen size in tests
2621
jest.mock('@hooks/useResponsiveLayout', () => jest.fn());

tests/ui/MonthListItemHeaderTest.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
1515
import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct';
1616

1717
jest.mock('@components/ConfirmedRoute.tsx');
18-
jest.mock('@libs/Navigation/Navigation', () => ({
19-
getActiveRouteWithoutParams: jest.fn(() => ''),
20-
isNavigationReady: jest.fn(() => Promise.resolve()),
21-
navigate: jest.fn(),
22-
getActiveRoute: jest.fn(() => ''),
23-
}));
18+
jest.mock('@libs/Navigation/Navigation');
2419

2520
// Mock useResponsiveLayout to control screen size in tests
2621
jest.mock('@hooks/useResponsiveLayout', () => jest.fn());

tests/ui/ReportListItemHeaderTest.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ import createRandomPolicy from '../utils/collections/policies';
1616
import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct';
1717

1818
jest.mock('@components/ConfirmedRoute.tsx');
19-
jest.mock('@libs/Navigation/Navigation', () => ({
20-
getActiveRouteWithoutParams: jest.fn(() => ''),
21-
isNavigationReady: jest.fn(() => Promise.resolve()),
22-
navigate: jest.fn(),
23-
getActiveRoute: jest.fn(() => ''),
24-
}));
19+
jest.mock('@libs/Navigation/Navigation');
2520
jest.mock('@components/AvatarWithDisplayName.tsx');
2621

2722
// Mock search context with all required SearchContextStateValue and SearchContextActionsValue fields

tests/ui/TransactionItemRowRBRTest.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ import {createRandomReport} from '../utils/collections/reports';
1616
import createRandomTransaction from '../utils/collections/transaction';
1717
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
1818

19-
jest.mock('@libs/Navigation/Navigation', () => ({
20-
getActiveRouteWithoutParams: jest.fn(() => ''),
21-
isNavigationReady: jest.fn(() => Promise.resolve()),
22-
navigate: jest.fn(),
23-
getActiveRoute: jest.fn(() => ''),
24-
}));
19+
jest.mock('@libs/Navigation/Navigation');
2520
jest.mock('@hooks/useAnimatedHighlightStyle');
2621

2722
const MOCK_TRANSACTION_ID = '1';

tests/ui/WeekListItemHeaderTest.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
1515
import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct';
1616

1717
jest.mock('@components/ConfirmedRoute.tsx');
18-
jest.mock('@libs/Navigation/Navigation', () => ({
19-
getActiveRouteWithoutParams: jest.fn(() => ''),
20-
isNavigationReady: jest.fn(() => Promise.resolve()),
21-
navigate: jest.fn(),
22-
getActiveRoute: jest.fn(() => ''),
23-
}));
18+
jest.mock('@libs/Navigation/Navigation');
2419

2520
// Mock useResponsiveLayout to control screen size in tests
2621
jest.mock('@hooks/useResponsiveLayout', () => jest.fn());

tests/ui/YearListItemHeaderTest.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
1515
import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct';
1616

1717
jest.mock('@components/ConfirmedRoute.tsx');
18-
jest.mock('@libs/Navigation/Navigation', () => ({
19-
getActiveRouteWithoutParams: jest.fn(() => ''),
20-
isNavigationReady: jest.fn(() => Promise.resolve()),
21-
navigate: jest.fn(),
22-
getActiveRoute: jest.fn(() => ''),
23-
}));
18+
jest.mock('@libs/Navigation/Navigation');
2419

2520
// Mock useResponsiveLayout to control screen size in tests
2621
jest.mock('@hooks/useResponsiveLayout', () => jest.fn());

0 commit comments

Comments
 (0)