From: Eduardo San Martin Morote Date: Tue, 16 Apr 2019 11:14:22 +0000 (+0200) Subject: test: test with non named locations X-Git-Tag: v4.0.0-alpha.0~446 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=624215ea6611d2311f18d0447dfd5a78a6c7692e;p=thirdparty%2Fvuejs%2Frouter.git test: test with non named locations --- diff --git a/__tests__/matcher.spec.js b/__tests__/matcher.spec.js index fe7717e7..19bfa9a5 100644 --- a/__tests__/matcher.spec.js +++ b/__tests__/matcher.spec.js @@ -56,6 +56,14 @@ describe('Router Matcher', () => { ) }) + it('resolves a normal path without name', () => { + assertRecordMatch( + { path: '/', component }, + { path: '/' }, + { name: undefined, path: '/', params: {} } + ) + }) + it('resolves a path with params', () => { assertRecordMatch( { path: '/users/:id', name: 'User', component }, @@ -71,6 +79,14 @@ describe('Router Matcher', () => { { name: 'User', params: { id: 'posva', other: 'hey' } } ) }) + + it('resolves a path with multiple params but no name', () => { + assertRecordMatch( + { path: '/users/:id/:other', component }, + { path: '/users/posva/hey' }, + { name: undefined, params: { id: 'posva', other: 'hey' } } + ) + }) }) describe('LocationAsName', () => { @@ -101,6 +117,19 @@ describe('Router Matcher', () => { ) }) + it('replace params even with no name', () => { + assertRecordMatch( + { path: '/users/:id/m/:role', component }, + { params: { id: 'posva', role: 'admin' } }, + { name: undefined, path: '/users/posva/m/admin' }, + { + path: '/users/ed/m/user', + name: undefined, + params: { id: 'ed', role: 'user' }, + } + ) + }) + it('replace params', () => { assertRecordMatch( { path: '/users/:id/m/:role', name: 'UserEdit', component }, @@ -130,6 +159,23 @@ describe('Router Matcher', () => { } ) }) + + it('keep params if not provided even with no name', () => { + assertRecordMatch( + { path: '/users/:id/m/:role', component }, + {}, + { + name: undefined, + path: '/users/ed/m/user', + params: { id: 'ed', role: 'user' }, + }, + { + path: '/users/ed/m/user', + name: undefined, + params: { id: 'ed', role: 'user' }, + } + ) + }) }) }) }) diff --git a/explorations/html5.ts b/explorations/html5.ts index befece23..eb03b491 100644 --- a/explorations/html5.ts +++ b/explorations/html5.ts @@ -24,7 +24,7 @@ h.listen((to, from, { type }) => { console.log(`popstate(${type})`, { to, from }) }) -r.push('/multiple/one/two') +// r.push('/multiple/one/two') // h.push('/hey') // h.push('/hey?lol') @@ -33,30 +33,30 @@ r.push('/multiple/one/two') // h.replace('/bar') // r.push('/about') -// r.push({ -// path: '/', -// }) - -// r.push({ -// name: 'user', -// params: { -// id: '6', -// }, -// }) - -// r.push({ -// name: 'user', -// params: { -// id: '5', -// }, -// }) - -// r.push({ -// params: { -// id: 'no-name', -// }, -// }) - -// r.push({ -// hash: '#hey', -// }) +r.push({ + path: '/', +}) + +r.push({ + name: 'user', + params: { + id: '6', + }, +}) + +r.push({ + name: 'user', + params: { + id: '5', + }, +}) + +r.push({ + params: { + id: 'no-name', + }, +}) + +r.push({ + hash: '#hey', +})