From: Eduardo San Martin Morote Date: Fri, 11 Oct 2019 10:29:24 +0000 (+0200) Subject: test: add repeated params tests for match ranking X-Git-Tag: v4.0.0-alpha.0~206 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=76d6eaba8e70268e750e8816048a6abde9caea8c;p=thirdparty%2Fvuejs%2Frouter.git test: add repeated params tests for match ranking --- diff --git a/__tests__/matcher-ranking.spec.ts b/__tests__/matcher-ranking.spec.ts index 4a3b6b85..7613a1eb 100644 --- a/__tests__/matcher-ranking.spec.ts +++ b/__tests__/matcher-ranking.spec.ts @@ -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} */ - 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(.*)' + ]) + }) }) diff --git a/__tests__/matcher.spec.ts b/__tests__/matcher.spec.ts index 9b65df10..238d340c 100644 --- a/__tests__/matcher.spec.ts +++ b/__tests__/matcher.spec.ts @@ -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) {