]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: add test for params with nested routes
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 6 May 2019 16:17:46 +0000 (18:17 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 6 May 2019 16:17:46 +0000 (18:17 +0200)
__tests__/matcher.spec.js

index 47e65e76bf8037d98f51c17c5f2a9e1f11d6f471..6907b15eb7f9b9a1907d6f308858659e426ad08f 100644 (file)
@@ -450,6 +450,11 @@ describe('Router Matcher', () => {
       const ChildA = { path: 'a', name: 'child-a', component }
       const ChildB = { path: 'b', name: 'child-b', component }
       const ChildC = { path: 'c', name: 'child-c', component }
+      const ChildWithParam = { path: ':p', name: 'child-params', component }
+      const NestedChildWithParam = {
+        ...ChildWithParam,
+        name: 'nested-child-params',
+      }
       const NestedChildA = { ...ChildA, name: 'nested-child-a' }
       const NestedChildB = { ...ChildB, name: 'nested-child-b' }
       const NestedChildC = { ...ChildC, name: 'nested-child-c' }
@@ -459,6 +464,12 @@ describe('Router Matcher', () => {
         component,
         children: [NestedChildA, NestedChildB, NestedChildC],
       }
+      const NestedWithParam = {
+        path: 'nested/:n',
+        name: 'nested',
+        component,
+        children: [NestedChildWithParam],
+      }
 
       it('resolves children', () => {
         const Foo = {
@@ -562,6 +573,37 @@ describe('Router Matcher', () => {
           }
         )
       })
+
+      it('resolves nested children with params', () => {
+        const Foo = {
+          path: '/foo',
+          name: 'Foo',
+          component,
+          children: [NestedWithParam],
+        }
+        assertRecordMatch(
+          Foo,
+          { path: '/foo/nested/a/b' },
+          {
+            name: 'nested-child-params',
+            path: '/foo/nested/a/b',
+            params: { p: 'b', n: 'a' },
+            matched: [
+              Foo,
+              {
+                ...NestedWithParam,
+                path: `${Foo.path}/${NestedWithParam.path}`,
+              },
+              {
+                ...NestedChildWithParam,
+                path: `${Foo.path}/${NestedWithParam.path}/${
+                  NestedChildWithParam.path
+                }`,
+              },
+            ],
+          }
+        )
+      })
     })
   })
 })