2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-11 20:42:24 +03:00

fix: ignore data when its not an object (fixes: #253, #279, #297)

This commit is contained in:
pimlie
2019-03-08 13:45:57 +01:00
committed by Alexander Lichter
parent 23c3380c90
commit 7615f4120c
3 changed files with 32 additions and 6 deletions
+6 -4
View File
@@ -13,21 +13,23 @@ describe('getComponentOption', () => {
})
it('fetches the given option from the given component', () => {
const component = new Vue({ someOption: 'foo' })
const component = new Vue({ someOption: { foo: 'bar' } })
const mergedOption = getComponentOption({ component, keyName: 'someOption' })
expect(mergedOption).toEqual('foo')
expect(mergedOption.foo).toBeDefined()
expect(mergedOption.foo).toEqual('bar')
})
it('calls a function option, injecting the component as context', () => {
const component = new Vue({
name: 'Foobar',
someFunc() {
return this.$options.name
return { opt: this.$options.name }
}
})
const mergedOption = getComponentOption({ component, keyName: 'someFunc' })
// TODO: Should this be foobar or Foobar
expect(mergedOption).toEqual('Foobar')
expect(mergedOption.opt).toBeDefined()
expect(mergedOption.opt).toEqual('Foobar')
})
it('fetches deeply nested component options and merges them', () => {
+26 -1
View File
@@ -117,7 +117,7 @@ describe('getMetaInfo', () => {
{
vmid: 'a',
property: 'a',
content: 'b'
content: 'a'
}
],
base: [],
@@ -592,4 +592,29 @@ describe('getMetaInfo', () => {
__dangerouslyDisableSanitizersByTagID: {}
})
})
test('no errors when metaInfo returns nothing', () => {
const component = new Vue({
metaInfo() {},
el: document.createElement('div'),
render: h => h('div', null, [])
})
expect(getMetaInfo(component)).toEqual({
title: '',
titleChunk: '',
titleTemplate: '%s',
htmlAttrs: {},
headAttrs: {},
bodyAttrs: {},
meta: [],
base: [],
link: [],
style: [],
script: [],
noscript: [],
__dangerouslyDisableSanitizers: [],
__dangerouslyDisableSanitizersByTagID: {}
})
})
})