const { HTML5History } = require('../../src/history/html5')
const { Router } = require('../../src/router')
const fakePromise = require('faked-promise')
-const { NAVIGATION_TYPES, createDom } = require('../utils')
+const { NAVIGATION_TYPES, createDom, noGuard } = require('../utils')
/**
* @param {Partial<import('../../src/router').RouterOptions> & { routes: import('../../src/types').RouteRecord[]}} options
describe(navigationMethod, () => {
it('calls beforeRouteUpdate guards when changing params', async () => {
const router = createRouter({ routes })
- beforeRouteUpdate.mockImplementationOnce((to, from, next) => {
- next()
- })
+ beforeRouteUpdate.mockImplementationOnce(noGuard)
await router[navigationMethod]('/guard/valid')
// not called on initial navigation
expect(beforeRouteUpdate).not.toHaveBeenCalled()
const { HTML5History } = require('../../src/history/html5')
const { Router } = require('../../src/router')
const fakePromise = require('faked-promise')
-const { NAVIGATION_TYPES, createDom, tick } = require('../utils')
+const { NAVIGATION_TYPES, createDom, tick, noGuard } = require('../utils')
/**
* @param {Partial<import('../../src/router').RouterOptions> & { routes: import('../../src/types').RouteRecord[]}} options
const spy = jest.fn()
const router = createRouter({ routes })
router.beforeEach(spy)
- spy.mockImplementationOnce((to, from, next) => {
- next()
- })
+ spy.mockImplementationOnce(noGuard)
await router[navigationMethod]('/foo')
expect(spy).toHaveBeenCalledTimes(1)
})
const router = createRouter({ routes })
await router.push('/foo')
router.beforeEach(spy)
- spy.mockImplementationOnce((to, from, next) => {
- next()
- })
+ spy.mockImplementationOnce(noGuard)
await router[navigationMethod]('/foo')
expect(spy).not.toHaveBeenCalled()
})
const { HTML5History } = require('../../src/history/html5')
const { Router } = require('../../src/router')
const fakePromise = require('faked-promise')
-const { NAVIGATION_TYPES, createDom } = require('../utils')
+const { NAVIGATION_TYPES, createDom, noGuard } = require('../utils')
/**
* @param {Partial<import('../../src/router').RouterOptions> & { routes: import('../../src/types').RouteRecord[]}} options
describe(navigationMethod, () => {
it('calls beforeEnter guards on navigation', async () => {
const router = createRouter({ routes })
- beforeEnter.mockImplementationOnce((to, from, next) => {
- if (to.params.n !== 'valid') return next(false)
- next()
- })
+ beforeEnter.mockImplementationOnce(noGuard)
await router[navigationMethod]('/guard/valid')
expect(beforeEnter).toHaveBeenCalledTimes(1)
})
it('does not call beforeEnter guard if we were already on the page', async () => {
const router = createRouter({ routes })
- beforeEnter.mockImplementation((to, from, next) => {
- next()
- })
+ beforeEnter.mockImplementation(noGuard)
await router.push('/guard/one')
expect(beforeEnter).toHaveBeenCalledTimes(1)
await router[navigationMethod]('/guard/one')