]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: fix absolute paths tests
authorEduardo San Martin Morote <posva13@gmail.com>
Sat, 16 Aug 2025 13:11:25 +0000 (15:11 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Sat, 16 Aug 2025 13:11:25 +0000 (15:11 +0200)
packages/router/src/experimental/route-resolver/matcher-resolve.spec.ts
packages/router/src/experimental/route-resolver/resolver-static.spec.ts
packages/router/src/experimental/route-resolver/resolver-static.ts

index 27bab6028338e194d8d02d09b79a58b184b7cf7f..1b3051c2e68bd4a3c51d062876689087139efd73 100644 (file)
@@ -83,8 +83,6 @@ function compileRouteRecord(
     mergeOptions(PATH_PARSER_OPTIONS_DEFAULTS, record)
   )
 
-  // console.log({ record, parser })
-
   return {
     group: !isMatchable(record),
     name: record.name,
@@ -93,7 +91,6 @@ function compileRouteRecord(
     path: {
       match(value) {
         const params = parser.parse(value)
-        // console.log('🌟', parser.re, value, params)
         if (params) {
           return params
         }
@@ -212,9 +209,6 @@ describe('RouterMatcher.resolve', () => {
           fromLocation
         )
 
-    // console.log(matcher.getMatchers())
-    // console.log({ toLocation, resolved, expectedLocation, resolvedFrom })
-
     const result = matcher.resolve(
       // FIXME: should work now
       // @ts-expect-error
@@ -222,8 +216,6 @@ describe('RouterMatcher.resolve', () => {
       resolvedFrom === START_LOCATION ? undefined : resolvedFrom
     )
 
-    // console.log(result)
-
     if (
       expectedLocation.name === undefined ||
       expectedLocation.name !== NO_MATCH_LOCATION.name
index 1197b8b45d5d4e47be169889e7dc8a00e4783923..46c7a50e9d241609f3516603016cb2538e8fabab 100644 (file)
@@ -55,13 +55,13 @@ describe('StaticResolver', () => {
   })
 
   describe('resolve()', () => {
-    describe.todo('absolute locations as strings', () => {
+    describe('absolute locations as strings', () => {
       it('resolves string locations with no params', () => {
         const resolver = createStaticResolver([
           { name: 'root', path: EMPTY_PATH_PATTERN_MATCHER },
         ])
 
-        expect(resolver.resolve({ path: '/?a=a&b=b#h' })).toMatchObject({
+        expect(resolver.resolve('/?a=a&b=b#h')).toMatchObject({
           path: '/',
           params: {},
           query: { a: 'a', b: 'b' },
@@ -71,7 +71,7 @@ describe('StaticResolver', () => {
 
       it('resolves a not found string', () => {
         const resolver = createStaticResolver([])
-        expect(resolver.resolve({ path: '/bar?q=1#hash' })).toEqual({
+        expect(resolver.resolve('/bar?q=1#hash')).toEqual({
           ...NO_MATCH_LOCATION,
           fullPath: '/bar?q=1#hash',
           path: '/bar',
@@ -86,20 +86,18 @@ describe('StaticResolver', () => {
           { name: 'user-detail', path: USER_ID_PATH_PATTERN_MATCHER },
         ])
 
-        expect(resolver.resolve({ path: '/users/1?a=a&b=b#h' })).toMatchObject({
+        expect(resolver.resolve('/users/1?a=a&b=b#h')).toMatchObject({
           path: '/users/1',
           params: { id: 1 },
           query: { a: 'a', b: 'b' },
           hash: '#h',
         })
-        expect(resolver.resolve({ path: '/users/54?a=a&b=b#h' })).toMatchObject(
-          {
-            path: '/users/54',
-            params: { id: 54 },
-            query: { a: 'a', b: 'b' },
-            hash: '#h',
-          }
-        )
+        expect(resolver.resolve('/users/54?a=a&b=b#h')).toMatchObject({
+          path: '/users/54',
+          params: { id: 54 },
+          query: { a: 'a', b: 'b' },
+          hash: '#h',
+        })
       })
 
       it('resolve string locations with query', () => {
@@ -111,17 +109,15 @@ describe('StaticResolver', () => {
           },
         ])
 
-        expect(resolver.resolve({ path: '/foo?page=100&b=b#h' })).toMatchObject(
-          {
-            params: { page: 100 },
-            path: '/foo',
-            query: {
-              page: '100',
-              b: 'b',
-            },
-            hash: '#h',
-          }
-        )
+        expect(resolver.resolve('/foo?page=100&b=b#h')).toMatchObject({
+          params: { page: 100 },
+          path: '/foo',
+          query: {
+            page: '100',
+            b: 'b',
+          },
+          hash: '#h',
+        })
       })
 
       it('resolves string locations with hash', () => {
@@ -133,7 +129,7 @@ describe('StaticResolver', () => {
           },
         ])
 
-        expect(resolver.resolve({ path: '/foo?a=a&b=b#bar' })).toMatchObject({
+        expect(resolver.resolve('/foo?a=a&b=b#bar')).toMatchObject({
           hash: '#bar',
           params: { hash: 'bar' },
           path: '/foo',
@@ -151,9 +147,7 @@ describe('StaticResolver', () => {
           },
         ])
 
-        expect(
-          resolver.resolve({ path: '/users/24?page=100#bar' })
-        ).toMatchObject({
+        expect(resolver.resolve('/users/24?page=100#bar')).toMatchObject({
           params: { id: 24, page: 100, hash: 'bar' },
         })
       })
@@ -258,6 +252,19 @@ describe('StaticResolver', () => {
           hash: '',
         })
       })
+
+      it('treats object path as pathname only (no query/hash parsing)', () => {
+        const resolver = createStaticResolver([
+          { name: 'any-path', path: ANY_PATH_PATTERN_MATCHER },
+        ])
+        // Object with path containing query/hash should treat entire string as pathname
+        expect(resolver.resolve({ path: '/?a=a&b=b#h' })).toMatchObject({
+          path: '/?a=a&b=b#h', // Full string treated as path
+          query: {}, // Empty query
+          hash: '', // Empty hash
+          params: { pathMatch: '/?a=a&b=b#h' }, // Matcher sees full string
+        })
+      })
     })
 
     describe('named locations', () => {
index ec99ef669a7ce3385fe182aa7c460e68e431050d..8779213c895002595a4b517e53faaeee18b10025 100644 (file)
@@ -149,6 +149,8 @@ export function createStaticResolver<
   function resolve(
     ...[to, currentLocation]: _resolveArgs
   ): ResolverLocationResolved<TRecord> {
+    // named location, e.g. { name: 'foo', params }
+    // or relative location (second argument is current location)
     if (typeof to === 'object' && (to.name || to.path == null)) {
       // relative location by path or by name
       if (__DEV__ && to.name == null && currentLocation == null) {