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
)
})
+ 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 })
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()