From 684e9705af0fe7654875efbb5c952f96c95f49ae Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 26 Jun 2024 16:22:24 +0200 Subject: [PATCH] test: static matcher --- .../src/new-route-resolver/matcher-pattern.ts | 2 +- .../matchers/path-static.spec.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 packages/router/src/new-route-resolver/matchers/path-static.spec.ts 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') + }) +}) -- 2.47.2