From: Eduardo San Martin Morote Date: Wed, 26 Jun 2024 14:22:24 +0000 (+0200) Subject: test: static matcher X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ed433b07b0e4a1f4e8e4f5ee7d57eeb2a8a2bbb;p=thirdparty%2Fvuejs%2Frouter.git test: static matcher --- diff --git a/packages/router/src/new-route-resolver/matcher-pattern.ts b/packages/router/src/new-route-resolver/matcher-pattern.ts index 2e066bf8..3b2bbdbf 100644 --- a/packages/router/src/new-route-resolver/matcher-pattern.ts +++ b/packages/router/src/new-route-resolver/matcher-pattern.ts @@ -153,7 +153,7 @@ export class MatcherPatternImpl implements MatcherPattern { query: MatcherQueryParams hash: string }) { - // TODO: is this performant? Compare to a check with `null + // TODO: is this performant? bench compare to a check with `null try { return [ this.path.match(location.path), diff --git a/packages/router/src/new-route-resolver/matchers/path-static.spec.ts b/packages/router/src/new-route-resolver/matchers/path-static.spec.ts new file mode 100644 index 00000000..aae50551 --- /dev/null +++ b/packages/router/src/new-route-resolver/matchers/path-static.spec.ts @@ -0,0 +1,17 @@ +import { describe, expect, it } from 'vitest' +import { MatcherPathStatic } from './path-static' + +describe('PathStaticMatcher', () => { + it('matches', () => { + expect(new MatcherPathStatic('/').match('/')).toEqual({}) + expect(() => new MatcherPathStatic('/').match('/no')).toThrowError() + expect(new MatcherPathStatic('/ok/ok').match('/ok/ok')).toEqual({}) + expect(() => new MatcherPathStatic('/ok/ok').match('/ok/no')).toThrowError() + }) + + it('builds path', () => { + expect(new MatcherPathStatic('/').buildPath()).toBe('/') + expect(new MatcherPathStatic('/ok').buildPath()).toBe('/ok') + expect(new MatcherPathStatic('/ok/ok').buildPath()).toEqual('/ok/ok') + }) +})