From: Eduardo San Martin Morote Date: Mon, 6 May 2019 10:29:45 +0000 (+0200) Subject: test: add remove guards test X-Git-Tag: v4.0.0-alpha.0~393 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=462c0d6a0a9263cd8ec448960a784611705b5d22;p=thirdparty%2Fvuejs%2Frouter.git test: add remove guards test --- diff --git a/__tests__/guards/global-after.spec.js b/__tests__/guards/global-after.spec.js index 719d98bd..0f55274b 100644 --- a/__tests__/guards/global-after.spec.js +++ b/__tests__/guards/global-after.spec.js @@ -43,6 +43,15 @@ describe('router.afterEach', () => { ) }) + it('can be removed', async () => { + const spy = jest.fn() + const router = createRouter({ routes }) + const remove = router.afterEach(spy) + remove() + await router[navigationMethod]('/foo') + expect(spy).not.toHaveBeenCalled() + }) + it('does not call afterEach if navigation is cancelled', async () => { const spy = jest.fn() const router = createRouter({ routes }) diff --git a/__tests__/guards/global-beforeEach.spec.js b/__tests__/guards/global-beforeEach.spec.js index 82aae142..55c17205 100644 --- a/__tests__/guards/global-beforeEach.spec.js +++ b/__tests__/guards/global-beforeEach.spec.js @@ -43,6 +43,16 @@ describe('router.beforeEach', () => { expect(spy).toHaveBeenCalledTimes(1) }) + it('can be removed', async () => { + const spy = jest.fn() + const router = createRouter({ routes }) + const remove = router.beforeEach(spy) + remove() + spy.mockImplementationOnce(noGuard) + await router[navigationMethod]('/foo') + expect(spy).not.toHaveBeenCalled() + }) + it('does not call beforeEach guard if we were already on the page', async () => { const spy = jest.fn() const router = createRouter({ routes })