From: Eduardo San Martin Morote Date: Thu, 2 May 2019 20:40:53 +0000 (+0200) Subject: test: refactor using noGuard X-Git-Tag: v4.0.0-alpha.0~405 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b03e29c11f965c5297ecba2870c60e22f8d6de0a;p=thirdparty%2Fvuejs%2Frouter.git test: refactor using noGuard --- diff --git a/__tests__/guards/component-beforeRouteUpdate.spec.js b/__tests__/guards/component-beforeRouteUpdate.spec.js index c3c15e37..2ea0dc1f 100644 --- a/__tests__/guards/component-beforeRouteUpdate.spec.js +++ b/__tests__/guards/component-beforeRouteUpdate.spec.js @@ -4,7 +4,7 @@ const expect = require('expect') 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 & { routes: import('../../src/types').RouteRecord[]}} options @@ -46,9 +46,7 @@ describe('beforeRouteUpdate', () => { 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() diff --git a/__tests__/guards/global-beforeEach.spec.js b/__tests__/guards/global-beforeEach.spec.js index fa833071..af51e4d0 100644 --- a/__tests__/guards/global-beforeEach.spec.js +++ b/__tests__/guards/global-beforeEach.spec.js @@ -4,7 +4,7 @@ const expect = require('expect') 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 & { routes: import('../../src/types').RouteRecord[]}} options @@ -36,9 +36,7 @@ describe('router.beforeEach', () => { 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) }) @@ -48,9 +46,7 @@ describe('router.beforeEach', () => { 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() }) diff --git a/__tests__/guards/route-beforeEnter.spec.js b/__tests__/guards/route-beforeEnter.spec.js index 5086e6dd..76532b0a 100644 --- a/__tests__/guards/route-beforeEnter.spec.js +++ b/__tests__/guards/route-beforeEnter.spec.js @@ -4,7 +4,7 @@ const expect = require('expect') 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 & { routes: import('../../src/types').RouteRecord[]}} options @@ -44,19 +44,14 @@ describe('beforeEnter', () => { 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')