@@ -4,6 +4,19 @@ import Navigation from '@libs/Navigation/Navigation';
44import navigationRef from '@libs/Navigation/navigationRef' ;
55import type { Route } from '@src/ROUTES' ;
66
7+ jest . mock ( '@libs/Navigation/navigationRef' , ( ) => {
8+ const navigationRefMock = {
9+ current : { getCurrentRoute : jest . fn ( ) } ,
10+ getRootState : jest . fn ( ) ,
11+ isReady : jest . fn ( ) ,
12+ } ;
13+
14+ return {
15+ __esModule : true ,
16+ default : navigationRefMock ,
17+ } ;
18+ } ) ;
19+
720jest . mock ( '@react-navigation/native' , ( ) => {
821 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
922 const actual = jest . requireActual ( '@react-navigation/native' ) as { getPathFromState : typeof GetPathFromState } ;
@@ -15,16 +28,19 @@ jest.mock('@react-navigation/native', () => {
1528
1629describe ( 'Navigation' , ( ) => {
1730 afterEach ( ( ) => {
18- jest . restoreAllMocks ( ) ;
31+ jest . clearAllMocks ( ) ;
1932 } ) ;
2033
2134 beforeEach ( ( ) => {
22- // Minimal stubs so getActiveRoute() can derive a path without rendering navigation containers.
23- const ref = navigationRef as typeof navigationRef & { current : { getCurrentRoute : ( ) => { name : string } } | null } ;
24- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
25- ref . current = { getCurrentRoute : jest . fn ( ) . mockReturnValue ( { name : 'test' } ) } as any ;
26- jest . spyOn ( navigationRef , 'getRootState' ) . mockReturnValue ( { } as unknown as ReturnType < typeof navigationRef . getRootState > ) ;
27- jest . spyOn ( navigationRef , 'isReady' ) . mockReturnValue ( true ) ;
35+ const navigationRefMock = navigationRef as typeof navigationRef & {
36+ current : { getCurrentRoute : jest . Mock } ;
37+ getRootState : jest . Mock ;
38+ isReady : jest . Mock ;
39+ } ;
40+
41+ navigationRefMock . current . getCurrentRoute . mockReturnValue ( { name : 'test' } ) ;
42+ navigationRefMock . getRootState . mockReturnValue ( { } as ReturnType < typeof navigationRef . getRootState > ) ;
43+ navigationRefMock . isReady . mockReturnValue ( true ) ;
2844 } ) ;
2945
3046 it ( 'Should correctly identify active routes' , ( ) => {
0 commit comments