From: Eduardo San Martin Morote Date: Fri, 1 May 2020 15:54:43 +0000 (+0200) Subject: test(warn): test warnings X-Git-Tag: v4.0.0-alpha.10~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3fe9812340bec2a31284ea9c33dfcbf4c6ea8e12;p=thirdparty%2Fvuejs%2Frouter.git test(warn): test warnings --- diff --git a/__tests__/warnings.spec.ts b/__tests__/warnings.spec.ts new file mode 100644 index 00000000..6e3c63a6 --- /dev/null +++ b/__tests__/warnings.spec.ts @@ -0,0 +1,41 @@ +import { mockWarn } from 'jest-mock-warn' +import { createMemoryHistory, createRouter } from '../src' +import { defineComponent } from 'vue' + +let component = defineComponent({}) + +describe('warnings', () => { + mockWarn() + it('warns on missing name and path for redirect', async () => { + const history = createMemoryHistory() + const router = createRouter({ + history, + routes: [ + { path: '/', component }, + { path: '/redirect', redirect: { params: { foo: 'f' } } }, + ], + }) + await router.push('/redirect').catch(() => {}) + expect('Invalid redirect found').toHaveBeenWarned() + }) + + it('warns when resolving a route with path and params', async () => { + const history = createMemoryHistory() + const router = createRouter({ + history, + routes: [{ path: '/:p', name: 'p', component }], + }) + router.resolve({ path: '/', params: { p: 'p' } }) + expect('Path "/" was passed with params').toHaveBeenWarned() + }) + + it('does not warn when resolving a route with path, params and name', async () => { + const history = createMemoryHistory() + const router = createRouter({ + history, + routes: [{ path: '/:p', name: 'p', component }], + }) + router.resolve({ path: '/p', name: 'p', params: { p: 'p' } }) + expect('Path "/" was passed with params').not.toHaveBeenWarned() + }) +}) diff --git a/src/router.ts b/src/router.ts index 76a90ec4..acefaa3d 100644 --- a/src/router.ts +++ b/src/router.ts @@ -353,6 +353,7 @@ export function createRouter(options: RouterOptions): Router { targetLocation.fullPath }". A redirect must contain a name or path.` ) + return Promise.reject(new Error('Invalid redirect')) } return pushWithRedirect( {