From: Eduardo San Martin Morote Date: Wed, 1 May 2019 09:30:02 +0000 (+0200) Subject: test: no afterGuard if navigation is cancelled X-Git-Tag: v4.0.0-alpha.0~427 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fade2bac139cb49549ab7cb7622d0844d24c8f30;p=thirdparty%2Fvuejs%2Frouter.git test: no afterGuard if navigation is cancelled --- diff --git a/__tests__/after-guards.spec.js b/__tests__/after-guards.spec.js index 5d46f16b..ead0ca25 100644 --- a/__tests__/after-guards.spec.js +++ b/__tests__/after-guards.spec.js @@ -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 & { 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 }) diff --git a/explorations/html5.ts b/explorations/html5.ts index 7e0b0720..8296a96b 100644 --- a/explorations/html5.ts +++ b/explorations/html5.ts @@ -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()