]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: test with non named locations
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 16 Apr 2019 11:14:22 +0000 (13:14 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 16 Apr 2019 11:14:22 +0000 (13:14 +0200)
__tests__/matcher.spec.js
explorations/html5.ts

index fe7717e7568b83b806bd644fb330d70ac92aa4fe..19bfa9a5fb1cadf80b9d6c3458f019d3b265693d 100644 (file)
@@ -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' },
+          }
+        )
+      })
     })
   })
 })
index befece23f8abee27ba95fe21ecebf1a8d00dd349..eb03b4917321d23e7070e246ae39c92312b90749 100644 (file)
@@ -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',
+})