Skip to content

Commit 1b68ef7

Browse files
committed
test: add alias tests to generateRouteRecords
Enable the todo test for merging alias properties and add tests for single, multiple, and dynamic alias paths.
1 parent 8af23d0 commit 1b68ef7

File tree

2 files changed

+88
-14
lines changed

2 files changed

+88
-14
lines changed

packages/router/src/unplugin/codegen/__snapshots__/generateRouteRecords.spec.ts.snap

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,49 @@ exports[`generateRouteRecord > route block > adds meta data 1`] = `
732732
]"
733733
`;
734734
735+
exports[`generateRouteRecord > route block > handles a single static alias 1`] = `
736+
"[
737+
{
738+
path: '/users',
739+
name: '/users',
740+
component: () => import('users.vue'),
741+
alias: ["/people"],
742+
/* no children */
743+
}
744+
]"
745+
`;
746+
747+
exports[`generateRouteRecord > route block > handles dynamic alias path 1`] = `
748+
"[
749+
{
750+
path: '/users',
751+
/* internal name: '/users' */
752+
/* no component */
753+
children: [
754+
{
755+
path: ':id',
756+
name: '/users/[id]',
757+
component: () => import('users/[id].vue'),
758+
alias: ["/people/:id"],
759+
/* no children */
760+
}
761+
],
762+
}
763+
]"
764+
`;
765+
766+
exports[`generateRouteRecord > route block > handles multiple aliases 1`] = `
767+
"[
768+
{
769+
path: '/users',
770+
name: '/users',
771+
component: () => import('users.vue'),
772+
alias: ["/people","/members"],
773+
/* no children */
774+
}
775+
]"
776+
`;
777+
735778
exports[`generateRouteRecord > route block > handles named views with empty route blocks 1`] = `
736779
"[
737780
{
@@ -750,6 +793,18 @@ exports[`generateRouteRecord > route block > handles named views with empty rout
750793
]"
751794
`;
752795
796+
exports[`generateRouteRecord > route block > merges alias properties 1`] = `
797+
"[
798+
{
799+
path: '/',
800+
name: '/',
801+
component: () => import('index.vue'),
802+
alias: ["/one","/two","/three"],
803+
/* no children */
804+
}
805+
]"
806+
`;
807+
753808
exports[`generateRouteRecord > route block > merges deep meta properties 1`] = `
754809
"[
755810
{

packages/router/src/unplugin/codegen/generateRouteRecords.spec.ts

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -302,28 +302,47 @@ describe('generateRouteRecord', () => {
302302
expect(generateRouteRecordSimple(tree)).toMatchSnapshot()
303303
})
304304

305-
// FIXME: allow aliases
306-
it.todo('merges alias properties', async () => {
305+
it('merges alias properties', async () => {
307306
const tree = new PrefixTree(DEFAULT_OPTIONS)
308307
const node = tree.insert('index', 'index.vue')
309308
node.setCustomRouteBlock('index', {
310-
alias: '/one',
309+
alias: ['/one'],
311310
})
312311
node.setCustomRouteBlock('index@named', {
313312
alias: ['/two', '/three'],
314313
})
315314

316-
expect(generateRouteRecordSimple(tree)).toMatchInlineSnapshot(`
317-
"[
318-
{
319-
path: '/',
320-
name: '/',
321-
component: () => import('index'),
322-
/* no props */
323-
/* no children */
324-
}
325-
]"
326-
`)
315+
expect(generateRouteRecordSimple(tree)).toMatchSnapshot()
316+
})
317+
318+
it('handles a single static alias', () => {
319+
const tree = new PrefixTree(DEFAULT_OPTIONS)
320+
const node = tree.insert('users', 'users.vue')
321+
node.setCustomRouteBlock('users', {
322+
alias: ['/people'],
323+
})
324+
325+
expect(generateRouteRecordSimple(tree)).toMatchSnapshot()
326+
})
327+
328+
it('handles multiple aliases', () => {
329+
const tree = new PrefixTree(DEFAULT_OPTIONS)
330+
const node = tree.insert('users', 'users.vue')
331+
node.setCustomRouteBlock('users', {
332+
alias: ['/people', '/members'],
333+
})
334+
335+
expect(generateRouteRecordSimple(tree)).toMatchSnapshot()
336+
})
337+
338+
it('handles dynamic alias path', () => {
339+
const tree = new PrefixTree(DEFAULT_OPTIONS)
340+
const node = tree.insert('users/[id]', 'users/[id].vue')
341+
node.setCustomRouteBlock('users/[id]', {
342+
alias: ['/people/:id'],
343+
})
344+
345+
expect(generateRouteRecordSimple(tree)).toMatchSnapshot()
327346
})
328347

329348
it('merges deep meta properties', async () => {

0 commit comments

Comments
 (0)