diff --git a/src/shared/nav-guards.js b/src/shared/nav-guards.js index b86c525..edbae81 100644 --- a/src/shared/nav-guards.js +++ b/src/shared/nav-guards.js @@ -3,6 +3,7 @@ import { isFunction } from '../utils/is-type' export function addNavGuards(vm) { // return when nav guards already added or no router exists if (vm.$root._vueMeta.navGuards || !vm.$root.$router) { + /* istanbul ignore next */ return } diff --git a/test/unit/components.test.js b/test/unit/components.test.js index 2a32113..f909afe 100644 --- a/test/unit/components.test.js +++ b/test/unit/components.test.js @@ -128,7 +128,7 @@ describe('client', () => { expect(context._uid).toBe(wrapper.vm._uid) }) - test('afterNavigation function is called', () => { + test('afterNavigation function is called with refreshOnce: true', () => { const Vue = loadVueMetaPlugin(false, { refreshOnceOnNavigation: true }) const afterNavigation = jest.fn() const component = Vue.component('nav-component', { @@ -160,4 +160,37 @@ describe('client', () => { guards.after() expect(afterNavigation).toHaveBeenCalled() }) + + test('afterNavigation function is called with refreshOnce: false', () => { + const Vue = loadVueMetaPlugin(false, { refreshOnceOnNavigation: false }) + const afterNavigation = jest.fn() + const component = Vue.component('nav-component', { + render: h => h('div'), + metaInfo: { afterNavigation } + }) + + const guards = {} + const wrapper = mount(component, { + localVue: Vue, + mocks: { + $router: { + beforeEach(fn) { + guards.before = fn + }, + afterEach(fn) { + guards.after = fn + } + } + } + }) + + expect(guards.before).toBeDefined() + expect(guards.after).toBeDefined() + + guards.before(null, null, () => {}) + expect(wrapper.vm.$root._vueMeta.paused).toBe(true) + + guards.after() + expect(afterNavigation).toHaveBeenCalled() + }) })