Skip to content

Commit 4ec689c

Browse files
committed
test: fix absolute paths tests
1 parent 96d8a89 commit 4ec689c

File tree

3 files changed

+36
-35
lines changed

3 files changed

+36
-35
lines changed

packages/router/src/experimental/route-resolver/matcher-resolve.spec.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ function compileRouteRecord(
8383
mergeOptions(PATH_PARSER_OPTIONS_DEFAULTS, record)
8484
)
8585

86-
// console.log({ record, parser })
87-
8886
return {
8987
group: !isMatchable(record),
9088
name: record.name,
@@ -93,7 +91,6 @@ function compileRouteRecord(
9391
path: {
9492
match(value) {
9593
const params = parser.parse(value)
96-
// console.log('🌟', parser.re, value, params)
9794
if (params) {
9895
return params
9996
}
@@ -212,18 +209,13 @@ describe('RouterMatcher.resolve', () => {
212209
fromLocation
213210
)
214211

215-
// console.log(matcher.getMatchers())
216-
// console.log({ toLocation, resolved, expectedLocation, resolvedFrom })
217-
218212
const result = matcher.resolve(
219213
// FIXME: should work now
220214
// @ts-expect-error
221215
toLocation,
222216
resolvedFrom === START_LOCATION ? undefined : resolvedFrom
223217
)
224218

225-
// console.log(result)
226-
227219
if (
228220
expectedLocation.name === undefined ||
229221
expectedLocation.name !== NO_MATCH_LOCATION.name

packages/router/src/experimental/route-resolver/resolver-static.spec.ts

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ describe('StaticResolver', () => {
5555
})
5656

5757
describe('resolve()', () => {
58-
describe.todo('absolute locations as strings', () => {
58+
describe('absolute locations as strings', () => {
5959
it('resolves string locations with no params', () => {
6060
const resolver = createStaticResolver([
6161
{ name: 'root', path: EMPTY_PATH_PATTERN_MATCHER },
6262
])
6363

64-
expect(resolver.resolve({ path: '/?a=a&b=b#h' })).toMatchObject({
64+
expect(resolver.resolve('/?a=a&b=b#h')).toMatchObject({
6565
path: '/',
6666
params: {},
6767
query: { a: 'a', b: 'b' },
@@ -71,7 +71,7 @@ describe('StaticResolver', () => {
7171

7272
it('resolves a not found string', () => {
7373
const resolver = createStaticResolver([])
74-
expect(resolver.resolve({ path: '/bar?q=1#hash' })).toEqual({
74+
expect(resolver.resolve('/bar?q=1#hash')).toEqual({
7575
...NO_MATCH_LOCATION,
7676
fullPath: '/bar?q=1#hash',
7777
path: '/bar',
@@ -86,20 +86,18 @@ describe('StaticResolver', () => {
8686
{ name: 'user-detail', path: USER_ID_PATH_PATTERN_MATCHER },
8787
])
8888

89-
expect(resolver.resolve({ path: '/users/1?a=a&b=b#h' })).toMatchObject({
89+
expect(resolver.resolve('/users/1?a=a&b=b#h')).toMatchObject({
9090
path: '/users/1',
9191
params: { id: 1 },
9292
query: { a: 'a', b: 'b' },
9393
hash: '#h',
9494
})
95-
expect(resolver.resolve({ path: '/users/54?a=a&b=b#h' })).toMatchObject(
96-
{
97-
path: '/users/54',
98-
params: { id: 54 },
99-
query: { a: 'a', b: 'b' },
100-
hash: '#h',
101-
}
102-
)
95+
expect(resolver.resolve('/users/54?a=a&b=b#h')).toMatchObject({
96+
path: '/users/54',
97+
params: { id: 54 },
98+
query: { a: 'a', b: 'b' },
99+
hash: '#h',
100+
})
103101
})
104102

105103
it('resolve string locations with query', () => {
@@ -111,17 +109,15 @@ describe('StaticResolver', () => {
111109
},
112110
])
113111

114-
expect(resolver.resolve({ path: '/foo?page=100&b=b#h' })).toMatchObject(
115-
{
116-
params: { page: 100 },
117-
path: '/foo',
118-
query: {
119-
page: '100',
120-
b: 'b',
121-
},
122-
hash: '#h',
123-
}
124-
)
112+
expect(resolver.resolve('/foo?page=100&b=b#h')).toMatchObject({
113+
params: { page: 100 },
114+
path: '/foo',
115+
query: {
116+
page: '100',
117+
b: 'b',
118+
},
119+
hash: '#h',
120+
})
125121
})
126122

127123
it('resolves string locations with hash', () => {
@@ -133,7 +129,7 @@ describe('StaticResolver', () => {
133129
},
134130
])
135131

136-
expect(resolver.resolve({ path: '/foo?a=a&b=b#bar' })).toMatchObject({
132+
expect(resolver.resolve('/foo?a=a&b=b#bar')).toMatchObject({
137133
hash: '#bar',
138134
params: { hash: 'bar' },
139135
path: '/foo',
@@ -151,9 +147,7 @@ describe('StaticResolver', () => {
151147
},
152148
])
153149

154-
expect(
155-
resolver.resolve({ path: '/users/24?page=100#bar' })
156-
).toMatchObject({
150+
expect(resolver.resolve('/users/24?page=100#bar')).toMatchObject({
157151
params: { id: 24, page: 100, hash: 'bar' },
158152
})
159153
})
@@ -258,6 +252,19 @@ describe('StaticResolver', () => {
258252
hash: '',
259253
})
260254
})
255+
256+
it('treats object path as pathname only (no query/hash parsing)', () => {
257+
const resolver = createStaticResolver([
258+
{ name: 'any-path', path: ANY_PATH_PATTERN_MATCHER },
259+
])
260+
// Object with path containing query/hash should treat entire string as pathname
261+
expect(resolver.resolve({ path: '/?a=a&b=b#h' })).toMatchObject({
262+
path: '/?a=a&b=b#h', // Full string treated as path
263+
query: {}, // Empty query
264+
hash: '', // Empty hash
265+
params: { pathMatch: '/?a=a&b=b#h' }, // Matcher sees full string
266+
})
267+
})
261268
})
262269

263270
describe('named locations', () => {

packages/router/src/experimental/route-resolver/resolver-static.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ export function createStaticResolver<
149149
function resolve(
150150
...[to, currentLocation]: _resolveArgs
151151
): ResolverLocationResolved<TRecord> {
152+
// named location, e.g. { name: 'foo', params }
153+
// or relative location (second argument is current location)
152154
if (typeof to === 'object' && (to.name || to.path == null)) {
153155
// relative location by path or by name
154156
if (__DEV__ && to.name == null && currentLocation == null) {

0 commit comments

Comments
 (0)