From: Eduardo San Martin Morote Date: Tue, 7 Apr 2020 12:23:37 +0000 (+0200) Subject: test: test missing param error X-Git-Tag: v4.0.0-alpha.5~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8bbed1b60219b32cb390745fb8ac297294efbf90;p=thirdparty%2Fvuejs%2Frouter.git test: test missing param error --- diff --git a/__tests__/matcher/addingRemoving.spec.ts b/__tests__/matcher/addingRemoving.spec.ts index 40ec9f10..d6b313a3 100644 --- a/__tests__/matcher/addingRemoving.spec.ts +++ b/__tests__/matcher/addingRemoving.spec.ts @@ -1,5 +1,6 @@ import { createRouterMatcher } from '../../src/matcher' import { MatcherLocation } from '../../src/types' +import { mockWarn } from 'jest-mock-warn' const currentLocation = { path: '/' } as MatcherLocation // @ts-ignore @@ -350,4 +351,14 @@ describe('Matcher: adding and removing records', () => { expect(matcher.getRecordMatcher('child')).toBe(undefined) }) + + describe('warnings', () => { + mockWarn() + + // TODO: add warnings for invalid records + it.skip('warns if alias is missing a required param', () => { + createRouterMatcher([{ path: '/:id', alias: '/no-id', component }], {}) + expect('TODO').toHaveBeenWarned() + }) + }) }) diff --git a/__tests__/router.spec.ts b/__tests__/router.spec.ts index ab5bc145..b83afa99 100644 --- a/__tests__/router.spec.ts +++ b/__tests__/router.spec.ts @@ -211,6 +211,13 @@ describe('Router', () => { expect(router.currentRoute.value.hash).toBe('#two') }) + it('fails if required params are missing', async () => { + const { router } = await newRouter() + await expect( + router.push({ name: 'Param', params: {} }) + ).rejects.toThrowError(/missing required param "p"/i) + }) + describe('alias', () => { it('does not navigate to alias if already on original record', async () => { const { router } = await newRouter() diff --git a/src/components/View.ts b/src/components/View.ts index e408a32d..6da2f736 100644 --- a/src/components/View.ts +++ b/src/components/View.ts @@ -58,6 +58,7 @@ export function useView(options: UseViewOptions) { // if we mount, there is a matched record matchedRoute.value!.instances[unref(options.name)] = viewRef.value // TODO: trigger beforeRouteEnter hooks + // TODO: watch name to update the instance record } return (attrs: SetupContext['attrs']) => {