]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: add repeated params tests for match ranking
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 11 Oct 2019 10:29:24 +0000 (12:29 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 11 Oct 2019 10:29:24 +0000 (12:29 +0200)
__tests__/matcher-ranking.spec.ts
__tests__/matcher.spec.ts

index 4a3b6b8591445209c8af593fb1c2c78794ff81f8..7613a1ebf72391d6c78eb0cbd76282e82a49ac88 100644 (file)
@@ -1,4 +1,4 @@
-import { createRouteMatcher } from '../src/matcher'
+import { createRouteMatcher, RouteMatcher } from '../src/matcher'
 import { RegExpOptions } from 'path-to-regexp'
 import { RouteComponent } from '../src/types'
 
@@ -20,8 +20,9 @@ describe('createRouteMatcher', () => {
       return [pathOrCombined, options]
     })
 
-    /** @type {Array<RouteMatcher & { _options: RegExpOptions }>} */
-    const matchers = normalizedPaths
+    const matchers: Array<
+      RouteMatcher & { _options: RegExpOptions }
+    > = normalizedPaths
       .slice()
       // Because sorting order is conserved, allows to mismatch order on
       // routes with the same ranking
@@ -164,4 +165,15 @@ describe('createRouteMatcher', () => {
       '/a', // also matches /A
     ])
   })
+
+  it('ranks repeated params properly', () => {
+    checkPathOrder([
+      '/:a',
+      '/:a+',
+      '/:a?',
+      '/:a*',
+      // FIXME: this one should appear here but it appears before /:a*
+      // '/:a(.*)'
+    ])
+  })
 })
index 9b65df10d6403787c5001786b080950455f53bef..238d340c01f7e2f5a84655083f197d02a3fbba56 100644 (file)
@@ -74,16 +74,16 @@ describe('Router Matcher', () => {
 
     /**
      *
-     * @param {RouteRecord | RouteRecord[]} record Record or records we are testing the matcher against
-     * @param {MatcherLocation} location location we want to reolve against
-     * @param {MatcherLocationNormalized} [start] Optional currentLocation used when resolving
-     * @returns {any} error
+     * @param record Record or records we are testing the matcher against
+     * @param location location we want to reolve against
+     * @param [start] Optional currentLocation used when resolving
+     * @returns error
      */
     function assertErrorMatch(
       record: RouteRecord | RouteRecord[],
       location: MatcherLocation,
       start: MatcherLocationNormalized = START_LOCATION_NORMALIZED
-    ) {
+    ): any {
       try {
         assertRecordMatch(record, location, {}, start)
       } catch (error) {