From fa12530b3ec450338c52dea2873f6913ee3abaf0 Mon Sep 17 00:00:00 2001 From: Ricardo Gobbo de Souza Date: Mon, 28 Oct 2019 06:24:42 -0300 Subject: [PATCH] fix: call afterNavigation after nextTick (#478) * fix: afterNavigation * style: use arrow function --- src/shared/nav-guards.js | 10 ++++++---- test/unit/components.test.js | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/shared/nav-guards.js b/src/shared/nav-guards.js index c63d9251..135609ac 100644 --- a/src/shared/nav-guards.js +++ b/src/shared/nav-guards.js @@ -19,10 +19,12 @@ export function addNavGuards (rootVm) { }) router.afterEach(() => { - const { metaInfo } = resume(rootVm) + rootVm.$nextTick(() => { + const { metaInfo } = resume(rootVm) - if (metaInfo && isFunction(metaInfo.afterNavigation)) { - metaInfo.afterNavigation(metaInfo) - } + if (metaInfo && isFunction(metaInfo.afterNavigation)) { + metaInfo.afterNavigation(metaInfo) + } + }) }) } diff --git a/test/unit/components.test.js b/test/unit/components.test.js index 2b9e3d0c..5d01b20c 100644 --- a/test/unit/components.test.js +++ b/test/unit/components.test.js @@ -271,6 +271,8 @@ describe('components', () => { expect(wrapper.vm.$root._vueMeta.pausing).toBe(true) guards.after() + expect(afterNavigation).not.toHaveBeenCalled() + await vmTick(wrapper.vm) expect(afterNavigation).toHaveBeenCalled() }) @@ -306,6 +308,8 @@ describe('components', () => { expect(wrapper.vm.$root._vueMeta.pausing).toBe(true) guards.after() + expect(afterNavigation).not.toHaveBeenCalled() + await vmTick(wrapper.vm) expect(afterNavigation).toHaveBeenCalled() })