From: Eduardo San Martin Morote Date: Wed, 26 Feb 2020 10:36:56 +0000 (+0100) Subject: test: add matcher test for dynamic routing X-Git-Tag: v4.0.0-alpha.1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc45057126a5b39009bd6d482fa3d48591e0ebd5;p=thirdparty%2Fvuejs%2Frouter.git test: add matcher test for dynamic routing --- diff --git a/__tests__/matcher/addingRemoving.spec.ts b/__tests__/matcher/addingRemoving.spec.ts index 588bbae0..b377d35a 100644 --- a/__tests__/matcher/addingRemoving.spec.ts +++ b/__tests__/matcher/addingRemoving.spec.ts @@ -41,6 +41,25 @@ describe('normalizeRouteRecord', () => { }) }) + it('remove children but not parent', () => { + const matcher = createRouterMatcher( + [{ path: '/', component, name: 'home' }], + {} + ) + const remove = matcher.addRoute( + { path: 'foo', component, name: 'child' }, + matcher.getRecordMatcher('home') + ) + remove() + expect(matcher.resolve({ path: '/' }, currentLocation)).toMatchObject({ + name: 'home', + }) + expect(matcher.resolve({ path: '/foo' }, currentLocation)).toMatchObject({ + name: undefined, + matched: [], + }) + }) + it.todo('remove aliases') it.todo('remove aliases children') @@ -106,7 +125,6 @@ describe('normalizeRouteRecord', () => { }).toThrow() }) - it.todo('removes alias by name') it('removes children by name', () => { const matcher = createRouterMatcher([], {}) matcher.addRoute({ @@ -136,7 +154,29 @@ describe('normalizeRouteRecord', () => { }) }) - it.todo('removes children by name from parent') + it('removes children by name from parent', () => { + const matcher = createRouterMatcher([], {}) + matcher.addRoute({ + path: '/', + component, + name: 'home', + children: [ + // absolute path so it can work out + { path: '/about', name: 'child', component }, + ], + }) + + matcher.removeRoute('home') + + expect(matcher.resolve({ path: '/about' }, currentLocation)).toMatchObject({ + name: undefined, + matched: [], + }) + + expect(matcher.getRecordMatcher('child')).toBe(undefined) + }) + + it.todo('removes alias by name') it.todo('removes children alias by name') })