@@ -336,9 +336,30 @@ describe('Experimental Router', () => {
336336
337337 it . skip ( 'warns on null location during dev' , async ( ) => { } )
338338
339- it . skip ( 'removes null/undefined optional params when current location has it' , async ( ) => { } )
339+ it ( 'can pass an optional param' , async ( ) => {
340+ const { router } = await newRouter ( )
341+ expect (
342+ router . resolve ( { name : 'optional' , params : { p : 'a' } } )
343+ ) . toHaveProperty ( 'params' , { p : 'a' } )
344+ } )
345+
346+ it ( 'removes optional params when current location has it' , async ( ) => {
347+ const { router } = await newRouter ( )
340348
341- it ( 'keeps empty strings in optional params' , async ( ) => {
349+ await router . push ( { name : 'optional' , params : { p : 'a' } } )
350+ await router . push ( { name : 'optional' , params : { p : null } } )
351+ expect ( router . currentRoute . value . params ) . toEqual ( { p : null } )
352+
353+ await router . push ( { name : 'optional' , params : { p : 'a' } } )
354+ await router . push ( { name : 'optional' , params : { p : undefined } } )
355+ expect ( router . currentRoute . value . params ) . toEqual ( { p : null } )
356+
357+ await router . push ( { name : 'optional' , params : { p : 'a' } } )
358+ await router . push ( { name : 'optional' , params : { } } )
359+ expect ( router . currentRoute . value . params ) . toEqual ( { p : null } )
360+ } )
361+
362+ it ( 'keeps consistent optional null param value' , async ( ) => {
342363 const { router } = await newRouter ( )
343364 expect (
344365 router . resolve ( { name : 'optional' , params : { p : '' } } )
@@ -350,6 +371,25 @@ describe('Experimental Router', () => {
350371 'params' ,
351372 { p : null }
352373 )
374+ expect ( router . resolve ( { name : 'optional' } ) ) . toHaveProperty ( 'params' , {
375+ p : null ,
376+ } )
377+ expect ( router . resolve ( '/optional' ) . params ) . toEqual ( { p : null } )
378+ } )
379+
380+ it ( 'does not fail for missing optional params' , async ( ) => {
381+ const { router } = await newRouter ( )
382+ expect (
383+ router . resolve ( {
384+ name : 'optional' ,
385+ params : { } ,
386+ } )
387+ ) . toHaveProperty ( 'name' , 'optional' )
388+
389+ expect ( router . resolve ( { name : 'optional' } ) ) . toHaveProperty (
390+ 'name' ,
391+ 'optional'
392+ )
353393 } )
354394
355395 it ( 'navigates to same route record but different query' , async ( ) => {
@@ -374,8 +414,6 @@ describe('Experimental Router', () => {
374414
375415 it . skip ( 'fails with arrays for non repeatable params' , async ( ) => { } )
376416
377- it . skip ( 'does not fail for optional params' , async ( ) => { } )
378-
379417 it ( 'can redirect to a star route when encoding the param' , ( ) => {
380418 const testCatchAllMatcher = new MatcherPatternPathDynamic (
381419 / ^ \/ ( .* ) $ / ,
0 commit comments