expect(router.currentRoute.value.path).toBe('/add')
})
- describe('Warnings', () => {
- it.skip('avoid infinite redirection loops', async () => {
- const history = createMemoryHistory()
- let calls = 0
- const beforeEnter = jest.fn((to, from, next) => {
- if (++calls > 1000) throw new Error('1000 calls')
- next(to.path)
- })
- const { router } = await newRouter({
- history,
- routes: [{ path: '/foo', component: components.Home, beforeEnter }],
- })
- await expect(router.push('/foo')).resolves.toBe(undefined)
- })
-
- it.todo('avoid infinite redirection loops when doing router.back()')
-
- it('warns if `next` is called twice', async () => {
- const { router } = await newRouter()
- router.beforeEach((to, from, next) => {
- next()
- next()
- })
- await router.push('/foo')
- expect(
- 'It should be called exactly one time in each navigation guard'
- ).toHaveBeenWarned()
- })
- })
-
describe('alias', () => {
it('does not navigate to alias if already on original record', async () => {
const { router } = await newRouter()
'Detected an infinite redirection in a navigation guard when going from "/" to "/b"'
).toHaveBeenWarned()
})
+
+ it('warns if `next` is called twice', async () => {
+ const router = createRouter({
+ history: createMemoryHistory(),
+ routes: [
+ { path: '/', component },
+ { path: '/foo', component },
+ ],
+ })
+ router.beforeEach((to, from, next) => {
+ next()
+ next()
+ })
+ await router.push('/foo')
+ expect(
+ 'It should be called exactly one time in each navigation guard'
+ ).toHaveBeenWarned()
+ })
})