From: Eduardo San Martin Morote Date: Thu, 6 Aug 2020 14:13:33 +0000 (+0200) Subject: test: move warning test to its own spec X-Git-Tag: v4.0.0-beta.7~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61022a6680f4cae14baf10582068b454218d530d;p=thirdparty%2Fvuejs%2Frouter.git test: move warning test to its own spec --- diff --git a/__tests__/router.spec.ts b/__tests__/router.spec.ts index 9fd38498..e45dca12 100644 --- a/__tests__/router.spec.ts +++ b/__tests__/router.spec.ts @@ -352,36 +352,6 @@ describe('Router', () => { 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() diff --git a/__tests__/warnings.spec.ts b/__tests__/warnings.spec.ts index 5cba0f90..4dfa8ac5 100644 --- a/__tests__/warnings.spec.ts +++ b/__tests__/warnings.spec.ts @@ -207,4 +207,22 @@ describe('warnings', () => { '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() + }) })