]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: static matcher
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 26 Jun 2024 14:22:24 +0000 (16:22 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 4 Dec 2024 15:10:35 +0000 (16:10 +0100)
packages/router/src/new-route-resolver/matcher-pattern.ts
packages/router/src/new-route-resolver/matchers/path-static.spec.ts [new file with mode: 0644]

index 2e066bf87ab34a39e4bcacf59a67c0c659ff9ce0..3b2bbdbfde1823cc63bb3a2b23f5c8a0f8d68a69 100644 (file)
@@ -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 (file)
index 0000000..aae5055
--- /dev/null
@@ -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')
+  })
+})