File tree Expand file tree Collapse file tree 4 files changed +31
-4
lines changed Expand file tree Collapse file tree 4 files changed +31
-4
lines changed Original file line number Diff line number Diff line change 11# Changelog  
22
3+ ## [ Unreleased] ( https://github.com/Instabug/Instabug-React-Native/compare/v13.3.0...dev )  
4+ 
5+ ### Added  
6+ 
7+ -  Add support for Expo Router navigation tracking ([ #1270  ] ( https://github.com/Instabug/Instabug-React-Native/pull/1270 ) ).
8+ 
39## [ 13.3.0] ( https://github.com/Instabug/Instabug-React-Native/compare/v13.2.0...v13.3.0 )  (August 4, 2024) 
410
511### Added  
Original file line number Diff line number Diff line change @@ -35,7 +35,9 @@ export const App: React.FC = () => {
3535  } ,  [ ] ) ; 
3636
3737  useEffect ( ( )  =>  { 
38-     Instabug . setNavigationListener ( navigationRef ) ; 
38+     const  unregisterListener  =  Instabug . setNavigationListener ( navigationRef ) ; 
39+ 
40+     return  unregisterListener ; 
3941  } ,  [ navigationRef ] ) ; 
4042
4143  return  ( 
Original file line number Diff line number Diff line change @@ -544,7 +544,7 @@ export const onStateChange = (state?: NavigationStateV5) => {
544544export  const  setNavigationListener  =  ( 
545545  navigationRef : NavigationContainerRefWithCurrent < ReactNavigation . RootParamList > , 
546546)  =>  { 
547-   navigationRef . addListener ( 'state' ,  ( )  =>  { 
547+   return   navigationRef . addListener ( 'state' ,  ( )  =>  { 
548548    onStateChange ( navigationRef . getRootState ( ) ) ; 
549549  } ) ; 
550550} ; 
Original file line number Diff line number Diff line change @@ -238,20 +238,39 @@ describe('Instabug Module', () => {
238238  } ) ; 
239239
240240  it ( 'setNavigationListener should call the onStateChange on a screen change' ,  async  ( )  =>  { 
241+     const  mockedState  =  {  routes : [ {  name : 'ScreenName'  } ] ,  index : 0  } ; 
242+ 
241243    const  mockNavigationContainerRef  =  { 
242244      current : null , 
243245      navigate : jest . fn ( ) , 
244246      reset : jest . fn ( ) , 
245247      goBack : jest . fn ( ) , 
246248      dispatch : jest . fn ( ) , 
247-       getRootState : jest . fn ( ) , 
249+       getRootState : ( )   =>   mockedState , 
248250      canGoBack : jest . fn ( ) , 
249-       addListener : jest . fn ( ) , 
251+ 
252+       addListener : jest . fn ( ( event ,  callback )  =>  { 
253+         expect ( event ) . toBe ( 'state' ) ; 
254+         callback ( mockedState ) ; 
255+         return  jest . fn ( ) ; 
256+       } ) , 
250257      removeListener : jest . fn ( ) , 
251258    }  as  unknown  as  NavigationContainerRefWithCurrent < ReactNavigation . RootParamList > ; 
252259
260+     const  onStateChangeMock  =  jest . fn ( ) ; 
261+ 
262+     jest . spyOn ( Instabug ,  'onStateChange' ) . mockImplementation ( onStateChangeMock ) ; 
263+ 
253264    Instabug . setNavigationListener ( mockNavigationContainerRef ) ; 
265+ 
254266    expect ( mockNavigationContainerRef . addListener ) . toBeCalledTimes ( 1 ) ; 
267+     expect ( mockNavigationContainerRef . addListener ) . toHaveBeenCalledWith ( 
268+       'state' , 
269+       expect . any ( Function ) , 
270+     ) ; 
271+ 
272+     expect ( onStateChangeMock ) . toBeCalledTimes ( 1 ) ; 
273+     expect ( onStateChangeMock ) . toHaveBeenCalledWith ( mockNavigationContainerRef . getRootState ( ) ) ; 
255274  } ) ; 
256275
257276  it ( 'should call the native method init' ,  ( )  =>  { 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments