]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: test missing param error
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 7 Apr 2020 12:23:37 +0000 (14:23 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 7 Apr 2020 12:23:37 +0000 (14:23 +0200)
__tests__/matcher/addingRemoving.spec.ts
__tests__/router.spec.ts
src/components/View.ts

index 40ec9f10c42b9e1e93635b50a7fa964d2d62e37b..d6b313a3aae7529df768120488e4eb2f823bdc44 100644 (file)
@@ -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()
+    })
+  })
 })
index ab5bc14585950d8cda682304c2d9f5ecff50e0ad..b83afa996c214ad5ad14e344a538398e252046bf 100644 (file)
@@ -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()
index e408a32d0eb21f362bad302ffcc11c95ae010060..6da2f73694678a2a994a0af5766bec021a5d672b 100644 (file)
@@ -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']) => {