From d136f25aa64f1fa6f9afc80785722b777934268d Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Thu, 2 May 2019 15:04:35 +0200 Subject: [PATCH] test: add test with lazy loaded beforeRouteLeave --- .../guards/component-beforeRouteLeave.spec.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/__tests__/guards/component-beforeRouteLeave.spec.js b/__tests__/guards/component-beforeRouteLeave.spec.js index ad25fdeb..caab1a6e 100644 --- a/__tests__/guards/component-beforeRouteLeave.spec.js +++ b/__tests__/guards/component-beforeRouteLeave.spec.js @@ -57,6 +57,25 @@ describe('beforeRouteLeave', () => { expect(beforeRouteLeave).toHaveBeenCalledTimes(1) }) + it('works when a lazy loaded component', async () => { + const router = createRouter({ + routes: [ + ...routes, + { + path: '/lazy', + component: () => Promise.resolve({ ...Foo, beforeRouteLeave }), + }, + ], + }) + beforeRouteLeave.mockImplementationOnce((to, from, next) => { + next() + }) + await router.push('/lazy') + expect(beforeRouteLeave).not.toHaveBeenCalled() + await router[navigationMethod]('/foo') + expect(beforeRouteLeave).toHaveBeenCalledTimes(1) + }) + it('can cancel navigation', async () => { const router = createRouter({ routes }) beforeRouteLeave.mockImplementationOnce(async (to, from, next) => { -- 2.47.3