@@ -107,6 +107,37 @@ describe('generateRouteRecordQuery', () => {
107107 ` )
108108 } )
109109
110+ it ( "emits identical query code for parser: 'string' and no parser" , ( ) => {
111+ const treeNone = new PrefixTree ( DEFAULT_OPTIONS )
112+ const nodeNone = treeNone . insert ( 'a' , 'a.vue' )
113+ nodeNone . value . setEditOverride ( 'params' , {
114+ query : { search : { } } ,
115+ } )
116+
117+ const treeString = new PrefixTree ( DEFAULT_OPTIONS )
118+ const nodeString = treeString . insert ( 'a' , 'a.vue' )
119+ nodeString . value . setEditOverride ( 'params' , {
120+ query : { search : { parser : 'string' } } ,
121+ } )
122+
123+ const noneImports = new ImportsMap ( )
124+ const stringImports = new ImportsMap ( )
125+
126+ const noneCode = generateRouteRecordQuery ( {
127+ importsMap : noneImports ,
128+ node : nodeNone ,
129+ paramParsersMap : new Map ( ) ,
130+ } )
131+ const stringCode = generateRouteRecordQuery ( {
132+ importsMap : stringImports ,
133+ node : nodeString ,
134+ paramParsersMap : new Map ( ) ,
135+ } )
136+
137+ expect ( stringCode ) . toBe ( noneCode )
138+ expect ( stringImports . toString ( ) ) . toBe ( noneImports . toString ( ) )
139+ } )
140+
110141 it ( 'generates query property with multiple query params' , ( ) => {
111142 const node = new PrefixTree ( DEFAULT_OPTIONS ) . insert ( 'a' , 'a.vue' )
112143 node . value . setEditOverride ( 'params' , {
@@ -371,6 +402,37 @@ describe('generateRouteRecord', () => {
371402 })"
372403 ` )
373404 } )
405+
406+ it ( 'emits identical path code for [id=string] and [id]' , ( ) => {
407+ const treeNone = new PrefixTree ( DEFAULT_OPTIONS )
408+ const treeString = new PrefixTree ( DEFAULT_OPTIONS )
409+
410+ const noneImports = new ImportsMap ( )
411+ const stringImports = new ImportsMap ( )
412+
413+ const noneCode = generateRouteRecord ( {
414+ node : treeNone . insert ( 'p/[id]' , 'p/[id].vue' ) ,
415+ parentVar : null ,
416+ parentNode : null ,
417+ state : { id : 0 , matchableRecords : [ ] } ,
418+ options : DEFAULT_OPTIONS ,
419+ importsMap : noneImports ,
420+ paramParsersMap : new Map ( ) ,
421+ } )
422+ const stringCode = generateRouteRecord ( {
423+ node : treeString . insert ( 'p/[id=string]' , 'p/[id=string].vue' ) ,
424+ parentVar : null ,
425+ parentNode : null ,
426+ state : { id : 0 , matchableRecords : [ ] } ,
427+ options : DEFAULT_OPTIONS ,
428+ importsMap : stringImports ,
429+ paramParsersMap : new Map ( ) ,
430+ } )
431+
432+ // file paths differ between fixtures; align them before comparison
433+ expect ( stringCode . replace ( / \[ i d = s t r i n g \] / g, '[id]' ) ) . toBe ( noneCode )
434+ expect ( stringImports . toString ( ) ) . toBe ( noneImports . toString ( ) )
435+ } )
374436} )
375437
376438describe ( 'generateRouteResolver' , ( ) => {
0 commit comments