]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: redirect and redirectedFrom
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 16 Mar 2020 08:52:37 +0000 (09:52 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 16 Mar 2020 08:52:37 +0000 (09:52 +0100)
__tests__/router.spec.ts

index 4e3bd4d95b1f67c410af0a20bf569231327ce743..fde357b2ce89dc35fbf379f52c3f00591a0e4f07 100644 (file)
@@ -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',
       })
     })