@@ -76,3 +76,73 @@ it('throws if NAVIGATE dispatched neither both key nor name', () => {
7676 'While calling navigate you need to specify either name or key'
7777 ) ;
7878} ) ;
79+
80+ it ( 'throws if SET_PARAMS dispatched with both key and name' , ( ) => {
81+ const TestNavigator = ( props : any ) => {
82+ const { state, descriptors } = useNavigationBuilder ( MockRouter , props ) ;
83+
84+ return descriptors [ state . routes [ state . index ] . key ] . render ( ) ;
85+ } ;
86+
87+ const FooScreen = ( props : any ) => {
88+ React . useEffect ( ( ) => {
89+ props . navigation . setParams ( { } , { key : '1' , name : '2' } ) ;
90+ // eslint-disable-next-line react-hooks/exhaustive-deps
91+ } , [ ] ) ;
92+
93+ return null ;
94+ } ;
95+
96+ const onStateChange = jest . fn ( ) ;
97+
98+ const element = (
99+ < NavigationContainer onStateChange = { onStateChange } >
100+ < TestNavigator initialRouteName = "foo" >
101+ < Screen
102+ name = "foo"
103+ component = { FooScreen }
104+ initialParams = { { count : 10 } }
105+ />
106+ </ TestNavigator >
107+ </ NavigationContainer >
108+ ) ;
109+
110+ expect ( ( ) => render ( element ) . update ( element ) ) . toThrowError (
111+ 'While calling setState with given second param you need to specify either name or key'
112+ ) ;
113+ } ) ;
114+
115+ it ( 'throws if SET_PARAMS dispatched neither both key nor name' , ( ) => {
116+ const TestNavigator = ( props : any ) => {
117+ const { state, descriptors } = useNavigationBuilder ( MockRouter , props ) ;
118+
119+ return descriptors [ state . routes [ state . index ] . key ] . render ( ) ;
120+ } ;
121+
122+ const FooScreen = ( props : any ) => {
123+ React . useEffect ( ( ) => {
124+ props . navigation . setParams ( { } , { } ) ;
125+ // eslint-disable-next-line react-hooks/exhaustive-deps
126+ } , [ ] ) ;
127+
128+ return null ;
129+ } ;
130+
131+ const onStateChange = jest . fn ( ) ;
132+
133+ const element = (
134+ < NavigationContainer onStateChange = { onStateChange } >
135+ < TestNavigator initialRouteName = "foo" >
136+ < Screen
137+ name = "foo"
138+ component = { FooScreen }
139+ initialParams = { { count : 10 } }
140+ />
141+ </ TestNavigator >
142+ </ NavigationContainer >
143+ ) ;
144+
145+ expect ( ( ) => render ( element ) . update ( element ) ) . toThrowError (
146+ 'While calling setState with given second param you need to specify either name or key'
147+ ) ;
148+ } ) ;
0 commit comments