|
1 | 1 | import { describe, expect, it } from 'vitest' |
2 | 2 | import { createFixedResolver } from './resolver-fixed' |
3 | | -import { NO_MATCH_LOCATION } from './resolver-abstract' |
| 3 | +import { MatcherLocationRaw, NO_MATCH_LOCATION } from './resolver-abstract' |
4 | 4 | import { |
5 | 5 | EmptyParams, |
6 | 6 | MatcherPatternHash, |
@@ -266,6 +266,37 @@ describe('fixed resolver', () => { |
266 | 266 | }) |
267 | 267 | }) |
268 | 268 |
|
| 269 | + it('keeps extra properties like state and replace from target location', () => { |
| 270 | + const resolver = createFixedResolver([ |
| 271 | + { name: 'any-path', path: ANY_PATH_PATTERN_MATCHER }, |
| 272 | + ]) |
| 273 | + |
| 274 | + const currentLocation = resolver.resolve({ path: '/bar' }) |
| 275 | + |
| 276 | + // extra parameters that should be preserved |
| 277 | + const extra = { state: { a: 1 }, replace: true } |
| 278 | + |
| 279 | + for (const path of ['foo', './foo', '../foo']) { |
| 280 | + expect( |
| 281 | + resolver.resolve( |
| 282 | + { |
| 283 | + // done this way because TS accepts this kind of combination |
| 284 | + path, |
| 285 | + ...extra, |
| 286 | + }, |
| 287 | + currentLocation |
| 288 | + ) |
| 289 | + ).toMatchObject({ |
| 290 | + params: {}, |
| 291 | + path: '/foo', |
| 292 | + query: {}, |
| 293 | + hash: {}, |
| 294 | + state: { a: 1 }, |
| 295 | + replace: true, |
| 296 | + }) |
| 297 | + } |
| 298 | + }) |
| 299 | + |
269 | 300 | it('resolves relative object locations', () => { |
270 | 301 | const resolver = createFixedResolver([ |
271 | 302 | { name: 'any-path', path: ANY_PATH_PATTERN_MATCHER }, |
@@ -445,6 +476,30 @@ describe('fixed resolver', () => { |
445 | 476 | params: { pathMatch: '/?a=a&b=b#h' }, |
446 | 477 | }) |
447 | 478 | }) |
| 479 | + |
| 480 | + it('keeps extra properties like state and replace from target location', () => { |
| 481 | + const resolver = createFixedResolver([ |
| 482 | + { name: 'any-path', path: ANY_PATH_PATTERN_MATCHER }, |
| 483 | + ]) |
| 484 | + |
| 485 | + // extra parameters that should be preserved |
| 486 | + const extra = { state: { a: 1 }, replace: true } |
| 487 | + |
| 488 | + expect( |
| 489 | + resolver.resolve({ |
| 490 | + // done this way because TS accepts this kind of combination |
| 491 | + path: '/foo', |
| 492 | + ...extra, |
| 493 | + }) |
| 494 | + ).toMatchObject({ |
| 495 | + params: {}, |
| 496 | + path: '/foo', |
| 497 | + query: {}, |
| 498 | + hash: {}, |
| 499 | + state: { a: 1 }, |
| 500 | + replace: true, |
| 501 | + }) |
| 502 | + }) |
448 | 503 | }) |
449 | 504 |
|
450 | 505 | describe('named locations', () => { |
@@ -490,6 +545,32 @@ describe('fixed resolver', () => { |
490 | 545 | ).toThrowError('Record "nonexistent" not found') |
491 | 546 | }) |
492 | 547 |
|
| 548 | + it('keeps extra properties like state and replace from target location', () => { |
| 549 | + const resolver = createFixedResolver([ |
| 550 | + { name: 'home', path: EMPTY_PATH_PATTERN_MATCHER }, |
| 551 | + ]) |
| 552 | + |
| 553 | + // extra parameters that should be preserved |
| 554 | + const extra = { state: { a: 1 }, replace: true } |
| 555 | + |
| 556 | + expect( |
| 557 | + resolver.resolve({ |
| 558 | + // done this way because TS accepts this kind of combination |
| 559 | + name: 'home', |
| 560 | + params: {}, |
| 561 | + ...extra, |
| 562 | + }) |
| 563 | + ).toMatchObject({ |
| 564 | + name: 'home', |
| 565 | + params: {}, |
| 566 | + path: '/', |
| 567 | + query: {}, |
| 568 | + hash: {}, |
| 569 | + state: { a: 1 }, |
| 570 | + replace: true, |
| 571 | + }) |
| 572 | + }) |
| 573 | + |
493 | 574 | it('resolves named locations with explicit query', () => { |
494 | 575 | const resolver = createFixedResolver([ |
495 | 576 | { |
|
0 commit comments