From: Eduardo San Martin Morote Date: Thu, 2 May 2019 13:04:35 +0000 (+0200) Subject: test: add test with lazy loaded beforeRouteLeave X-Git-Tag: v4.0.0-alpha.0~412 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d136f25aa64f1fa6f9afc80785722b777934268d;p=thirdparty%2Fvuejs%2Frouter.git test: add test with lazy loaded beforeRouteLeave --- 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) => {