From 23f028b26ba0405f37f8c2733683004cc8feb6c9 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Mon, 6 May 2019 18:17:46 +0200 Subject: [PATCH] test: add test for params with nested routes --- __tests__/matcher.spec.js | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/__tests__/matcher.spec.js b/__tests__/matcher.spec.js index 47e65e76..6907b15e 100644 --- a/__tests__/matcher.spec.js +++ b/__tests__/matcher.spec.js @@ -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 + }`, + }, + ], + } + ) + }) }) }) }) -- 2.47.3