Skip to content

Commit 2fcf3b8

Browse files
committed
test: migrate more
1 parent b3fde1d commit 2fcf3b8

File tree

2 files changed

+259
-40
lines changed

2 files changed

+259
-40
lines changed

packages/router/__tests__/router.spec.ts

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ describe('Router', () => {
662662

663663
describe('redirectedFrom', () => {
664664
it('adds a redirectedFrom property with a redirect in record', async () => {
665-
const { router } = await newRouter({ history: createMemoryHistory() })
665+
const { router } = await newRouter()
666666
// go to a different route first
667667
await router.push('/foo')
668668
await router.push('/home')
@@ -674,7 +674,7 @@ describe('Router', () => {
674674
})
675675

676676
it('adds a redirectedFrom property with beforeEnter', async () => {
677-
const { router } = await newRouter({ history: createMemoryHistory() })
677+
const { router } = await newRouter()
678678
// go to a different route first
679679
await router.push('/foo')
680680
await router.push('/home-before')
@@ -688,8 +688,7 @@ describe('Router', () => {
688688

689689
describe('redirect', () => {
690690
it('handles one redirect from route record', async () => {
691-
const history = createMemoryHistory()
692-
const router = createRouter({ history, routes })
691+
const { router } = await newRouter()
693692
await expect(router.push('/to-foo')).resolves.toEqual(undefined)
694693
const loc = router.currentRoute.value
695694
expect(loc.name).toBe('Foo')
@@ -699,8 +698,7 @@ describe('Router', () => {
699698
})
700699

701700
it('only triggers guards once with a redirect option', async () => {
702-
const history = createMemoryHistory()
703-
const router = createRouter({ history, routes })
701+
const { router } = await newRouter()
704702
const spy = vi.fn((to, from) => {})
705703
router.beforeEach(spy)
706704
await router.push('/to-foo')
@@ -713,8 +711,7 @@ describe('Router', () => {
713711
})
714712

715713
it('handles a double redirect from route record', async () => {
716-
const history = createMemoryHistory()
717-
const router = createRouter({ history, routes })
714+
const { router } = await newRouter()
718715
await expect(router.push('/to-foo2')).resolves.toEqual(undefined)
719716
const loc = router.currentRoute.value
720717
expect(loc.name).toBe('Foo')
@@ -724,8 +721,7 @@ describe('Router', () => {
724721
})
725722

726723
it('handles query and hash passed in redirect string', async () => {
727-
const history = createMemoryHistory()
728-
const router = createRouter({ history, routes })
724+
const { router } = await newRouter()
729725
await expect(router.push('/to-foo-query')).resolves.toEqual(undefined)
730726
expect(router.currentRoute.value).toMatchObject({
731727
name: 'Foo',
@@ -740,8 +736,7 @@ describe('Router', () => {
740736
})
741737

742738
it('keeps query and hash when redirect is a string', async () => {
743-
const history = createMemoryHistory()
744-
const router = createRouter({ history, routes })
739+
const { router } = await newRouter()
745740
await expect(router.push('/to-foo?hey=foo#fa')).resolves.toEqual(
746741
undefined
747742
)
@@ -758,8 +753,7 @@ describe('Router', () => {
758753
})
759754

760755
it('keeps params, query and hash from targetLocation on redirect', async () => {
761-
const history = createMemoryHistory()
762-
const router = createRouter({ history, routes })
756+
const { router } = await newRouter()
763757
await expect(router.push('/to-p/1?hey=foo#fa')).resolves.toEqual(
764758
undefined
765759
)
@@ -775,8 +769,8 @@ describe('Router', () => {
775769
})
776770

777771
it('discard params on string redirect', async () => {
778-
const history = createMemoryHistory()
779-
const router = createRouter({ history, routes })
772+
const { router } = await newRouter()
773+
await router.push('/foo')
780774
await expect(router.push('/redirect-with-param/test')).resolves.toEqual(
781775
undefined
782776
)
@@ -792,8 +786,7 @@ describe('Router', () => {
792786
})
793787

794788
it('allows object in redirect', async () => {
795-
const history = createMemoryHistory()
796-
const router = createRouter({ history, routes })
789+
const { router } = await newRouter()
797790
await expect(router.push('/to-foo-named')).resolves.toEqual(undefined)
798791
const loc = router.currentRoute.value
799792
expect(loc.name).toBe('Foo')
@@ -821,8 +814,7 @@ describe('Router', () => {
821814
})
822815

823816
it('can pass on query and hash when redirecting', async () => {
824-
const history = createMemoryHistory()
825-
const router = createRouter({ history, routes })
817+
const { router } = await newRouter()
826818
await router.push('/inc-query-hash?n=3#fa')
827819
const loc = router.currentRoute.value
828820
expect(loc).toMatchObject({

0 commit comments

Comments
 (0)