]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: no afterGuard if navigation is cancelled
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 1 May 2019 09:30:02 +0000 (11:30 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 1 May 2019 09:30:02 +0000 (11:30 +0200)
__tests__/after-guards.spec.js
explorations/html5.ts

index 5d46f16b5d639e01080cdfb36952fced993f2f06..ead0ca2593a3889da4efc7e7275d51fac8011d63 100644 (file)
@@ -4,9 +4,6 @@ const expect = require('expect')
 const { HTML5History } = require('../src/history/html5')
 const { Router } = require('../src/router')
 const { JSDOM } = require('jsdom')
-const fakePromise = require('faked-promise')
-
-const tick = () => new Promise(resolve => process.nextTick(resolve))
 
 /**
  * @param {Partial<import('../src/router').RouterOptions> & { routes: import('../src/types').RouteRecord[]}} options
@@ -55,6 +52,17 @@ describe('router.afterEach', () => {
     )
   })
 
+  it('does not call afterEach if navigation is cancelled', async () => {
+    const spy = jest.fn()
+    const router = createRouter({ routes })
+    router.afterEach(spy)
+    router.beforeEach((to, from, next) => {
+      next(false) // cancel the navigation
+    })
+    await router.push('/foo').catch(err => {}) // ignore the error
+    expect(spy).not.toHaveBeenCalled()
+  })
+
   it.skip('calls afterEach guards on replace', async () => {
     const spy = jest.fn()
     const router = createRouter({ routes })
index 7e0b07202068b37918b22841298dec69b12bebd7..8296a96b3aba06efd663b0d30e502d9f13503739 100644 (file)
@@ -18,6 +18,14 @@ r.beforeEach((to, from, next) => {
   next()
 })
 
+r.afterEach((to, from) => {
+  console.log(
+    `After guard: from ${from.fullPath} to ${
+      to.fullPath
+    } | location = ${location.href.replace(location.origin, '')}`
+  )
+})
+
 r.beforeEach((to, from, next) => {
   console.log('second guard')
   next()