From 6ee41b34500da99c82d7c2040030cd4ebf0d1a2f Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Mon, 16 Mar 2020 09:52:37 +0100 Subject: [PATCH] test: redirect and redirectedFrom --- __tests__/router.spec.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/__tests__/router.spec.ts b/__tests__/router.spec.ts index 4e3bd4d9..fde357b2 100644 --- a/__tests__/router.spec.ts +++ b/__tests__/router.spec.ts @@ -310,9 +310,8 @@ describe('Router', () => { }) }) - describe('matcher', () => { - // TODO: rewrite after redirect refactor - it.skip('handles one redirect from route record', async () => { + describe('redirect', () => { + it('handles one redirect from route record', async () => { const history = createMemoryHistory() const router = createRouter({ history, routes }) const loc = await router.push('/to-foo') @@ -322,8 +321,17 @@ describe('Router', () => { }) }) - // TODO: rewrite after redirect refactor - it.skip('drops query and params on redirect if not provided', async () => { + it('handles a double redirect from route record', async () => { + const history = createMemoryHistory() + const router = createRouter({ history, routes }) + const loc = await router.push('/to-foo2') + expect(loc.name).toBe('Foo') + expect(loc.redirectedFrom).toMatchObject({ + path: '/to-foo2', + }) + }) + + it('drops query and params on redirect if not provided', async () => { const history = createMemoryHistory() const router = createRouter({ history, routes }) const loc = await router.push('/to-foo?hey=foo#fa') @@ -335,8 +343,7 @@ describe('Router', () => { }) }) - // TODO: rewrite after redirect refactor - it.skip('allows object in redirect', async () => { + it('allows object in redirect', async () => { const history = createMemoryHistory() const router = createRouter({ history, routes }) const loc = await router.push('/to-foo-named') @@ -346,8 +353,7 @@ describe('Router', () => { }) }) - // TODO: rewrite after redirect refactor - it.skip('can pass on query and hash when redirecting', async () => { + it('can pass on query and hash when redirecting', async () => { const history = createMemoryHistory() const router = createRouter({ history, routes }) const loc = await router.push('/inc-query-hash?n=3#fa') @@ -360,6 +366,8 @@ describe('Router', () => { }) expect(loc.redirectedFrom).toMatchObject({ fullPath: '/inc-query-hash?n=3#fa', + query: { n: '3' }, + hash: '#fa', path: '/inc-query-hash', }) }) -- 2.39.5