Skip to content

Commit 4c1c307

Browse files
Anoesjposva
andauthored
test: test if params are not duplicated in the tree (#597)
* test: test if params are not duplicated in the tree * refactor: change path --------- Co-authored-by: Eduardo San Martin Morote <[email protected]>
1 parent e7789e9 commit 4c1c307

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/core/tree.spec.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, it } from 'vitest'
22
import { DEFAULT_OPTIONS, resolveOptions } from '../options'
33
import { PrefixTree } from './tree'
4-
import { TreeNodeType } from './treeNodeValue'
4+
import { TreeNodeType, type TreeRouteParam } from './treeNodeValue'
55
import { resolve } from 'pathe'
66
import { mockWarn } from '../../tests/vitest-mock-warn'
77

@@ -419,6 +419,25 @@ describe('Tree', () => {
419419
expect(node.fullPath).toBe('/custom-child')
420420
})
421421

422+
// https://github.com/posva/unplugin-vue-router/pull/597
423+
// added because in Nuxt the result was different
424+
it('does not contain duplicated params when a child route overrides the path', () => {
425+
const tree = new PrefixTree(RESOLVED_OPTIONS)
426+
tree.insert('[a]', '[a].vue')
427+
const node = tree.insert('[a]/b', '[a]/b.vue')
428+
node.value.setOverride('', {
429+
path: '/:a()/new-b',
430+
})
431+
expect(node.params).toHaveLength(1)
432+
expect(node.params[0]).toEqual({
433+
paramName: 'a',
434+
isSplat: false,
435+
modifier: '',
436+
optional: false,
437+
repeatable: false,
438+
} satisfies TreeRouteParam)
439+
})
440+
422441
it('removes trailing slash from path but not from name', () => {
423442
const tree = new PrefixTree(RESOLVED_OPTIONS)
424443
tree.insert('a/index', 'a/index.vue')

0 commit comments

Comments
 (0)