mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-10 15:12:25 +03:00
test: add nav-guard tests for refresOnce false
This commit is contained in:
committed by
Alexander Lichter
parent
d717dbf4e1
commit
7cf4efd290
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user