mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-23 22:40:34 +03:00
chore: add test for changed fn context
This commit is contained in:
@@ -4,6 +4,7 @@ import { mount, defaultOptions, loadVueMetaPlugin } from './utils'
|
|||||||
import GoodbyeWorld from './fixtures/goodbye-world.vue'
|
import GoodbyeWorld from './fixtures/goodbye-world.vue'
|
||||||
import HelloWorld from './fixtures/hello-world.vue'
|
import HelloWorld from './fixtures/hello-world.vue'
|
||||||
import KeepAlive from './fixtures/keep-alive.vue'
|
import KeepAlive from './fixtures/keep-alive.vue'
|
||||||
|
import Changed from './fixtures/changed.vue'
|
||||||
|
|
||||||
const getMetaInfo = component => _getMetaInfo(defaultOptions, component)
|
const getMetaInfo = component => _getMetaInfo(defaultOptions, component)
|
||||||
|
|
||||||
@@ -76,4 +77,21 @@ describe('client', () => {
|
|||||||
const metaInfo = wrapper.vm.$meta().inject()
|
const metaInfo = wrapper.vm.$meta().inject()
|
||||||
expect(metaInfo.title.text()).toEqual('<title data-vue-meta="true">Hello World</title>')
|
expect(metaInfo.title.text()).toEqual('<title data-vue-meta="true">Hello World</title>')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('changed function is called', () => {
|
||||||
|
const parentComponent = new Vue({ render: h => h('div') })
|
||||||
|
const wrapper = mount(Changed, { localVue: Vue, parentComponent })
|
||||||
|
|
||||||
|
let context
|
||||||
|
const changed = jest.fn(function() {
|
||||||
|
context = this
|
||||||
|
})
|
||||||
|
wrapper.setData({ changed })
|
||||||
|
wrapper.setData({ childVisible: true })
|
||||||
|
|
||||||
|
wrapper.vm.$parent.$meta().refresh()
|
||||||
|
expect(changed).toHaveBeenCalledTimes(1)
|
||||||
|
// TODO: this isnt what the docs say
|
||||||
|
expect(context._uid).not.toBe(wrapper.vm._uid)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Vendored
+26
@@ -0,0 +1,26 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<hello-world v-if="childVisible"></hello-world>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import HelloWorld from './hello-world.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
HelloWorld
|
||||||
|
},
|
||||||
|
metaInfo() {
|
||||||
|
return {
|
||||||
|
changed: this.changed
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
childVisible: false,
|
||||||
|
changed: () => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user