@@ -421,6 +421,68 @@ it('updates route params with setParams', () => {
421421 } ) ;
422422} ) ;
423423
424+ it ( 'updates route params with setParams applied to parent' , ( ) => {
425+ const TestNavigator = ( props : any ) => {
426+ const { state, descriptors } = useNavigationBuilder ( MockRouter , props ) ;
427+
428+ return descriptors [ state . routes [ state . index ] . key ] . render ( ) ;
429+ } ;
430+
431+ let setParams : ( params : object ) => void = ( ) => undefined ;
432+
433+ const FooScreen = ( props : any ) => {
434+ const parent = props . navigation . dangerouslyGetParent ( ) ;
435+ if ( parent ) {
436+ setParams = parent . setParams ;
437+ }
438+
439+ return null ;
440+ } ;
441+
442+ const onStateChange = jest . fn ( ) ;
443+
444+ render (
445+ < NavigationContainer onStateChange = { onStateChange } >
446+ < TestNavigator initialRouteName = "foo" >
447+ < Screen name = "foo" >
448+ { ( ) => (
449+ < TestNavigator initialRouteName = "baz" >
450+ < Screen name = "baz" component = { FooScreen } />
451+ </ TestNavigator >
452+ ) }
453+ </ Screen >
454+ < Screen name = "bar" component = { jest . fn ( ) } />
455+ </ TestNavigator >
456+ </ NavigationContainer >
457+ ) ;
458+
459+ act ( ( ) => setParams ( { username : 'alice' } ) ) ;
460+
461+ expect ( onStateChange ) . toBeCalledTimes ( 1 ) ;
462+ expect ( onStateChange ) . lastCalledWith ( {
463+ index : 0 ,
464+ key : '0' ,
465+ routeNames : [ 'foo' , 'bar' ] ,
466+ routes : [
467+ { key : 'foo' , name : 'foo' , params : { username : 'alice' } } ,
468+ { key : 'bar' , name : 'bar' } ,
469+ ] ,
470+ } ) ;
471+
472+ act ( ( ) => setParams ( { age : 25 } ) ) ;
473+
474+ expect ( onStateChange ) . toBeCalledTimes ( 2 ) ;
475+ expect ( onStateChange ) . lastCalledWith ( {
476+ index : 0 ,
477+ key : '0' ,
478+ routeNames : [ 'foo' , 'bar' ] ,
479+ routes : [
480+ { key : 'foo' , name : 'foo' , params : { username : 'alice' , age : 25 } } ,
481+ { key : 'bar' , name : 'bar' } ,
482+ ] ,
483+ } ) ;
484+ } ) ;
485+
424486it ( 'handles change in route names' , ( ) => {
425487 const TestNavigator = ( props : any ) : any => {
426488 useNavigationBuilder ( MockRouter , props ) ;
@@ -491,7 +553,7 @@ it('throws if navigator is not inside a container', () => {
491553 ) ;
492554} ) ;
493555
494- it ( 'throws if muliple navigators rendered under one container' , ( ) => {
556+ it ( 'throws if multiple navigators rendered under one container' , ( ) => {
495557 const TestNavigator = ( props : any ) => {
496558 useNavigationBuilder ( MockRouter , props ) ;
497559 return null ;
0 commit comments