Skip to content

Commit

Permalink
Merge pull request #19 from Atinux/master
Browse files Browse the repository at this point in the history
Fix: merge array if vmid is undefined
  • Loading branch information
Declan de Wet authored Nov 14, 2016
2 parents 5808ab9 + 488d6d1 commit ace5030
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/vuex-async/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
export default {
metaInfo: {
meta: [
{ vmid: 'charset', charset: 'utf-8' }
{ charset: 'utf-8' }
]
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/webpack.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export default {

module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel' },
{ test: /\.vue$/, loader: 'vue' },
{ test: /\.json$/, loader: 'json' }
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' },
{ test: /\.vue$/, loader: 'vue-loader' },
{ test: /\.json$/, loader: 'json-loader' }
]
},

Expand Down
2 changes: 1 addition & 1 deletion src/shared/getMetaInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function _getMetaInfo (options = {}) {
let shared = false
for (let sourceIndex in source) {
const sourceItem = source[sourceIndex]
if (targetItem[tagIDKeyName] === sourceItem[tagIDKeyName]) {
if (targetItem[tagIDKeyName] && targetItem[tagIDKeyName] === sourceItem[tagIDKeyName]) {
shared = true
break
}
Expand Down
42 changes: 41 additions & 1 deletion test/getMetaInfo.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import Vue from 'vue'
import _getMetaInfo from '../src/shared/getMetaInfo'
import {
VUE_META_KEY_NAME,
VUE_META_ATTRIBUTE,
VUE_META_SERVER_RENDERED_ATTRIBUTE,
VUE_META_TAG_LIST_ID_KEY_NAME
} from '../src/shared/constants'

const getMetaInfo = _getMetaInfo()
// set some default options
const defaultOptions = {
keyName: VUE_META_KEY_NAME,
attribute: VUE_META_ATTRIBUTE,
ssrAttribute: VUE_META_SERVER_RENDERED_ATTRIBUTE,
tagIDKeyName: VUE_META_TAG_LIST_ID_KEY_NAME
}

const getMetaInfo = _getMetaInfo(defaultOptions)

describe('getMetaInfo', () => {
// const container = document.createElement('div')
Expand All @@ -25,4 +39,30 @@ describe('getMetaInfo', () => {
noscript: []
})
})

it('returns metaInfos when used in component', () => {
component = new Vue({
metaInfo: {
title: 'Hello',
meta: [
{ charset: 'utf-8' }
]
}
})
expect(getMetaInfo(component)).to.eql({
title: 'Hello',
titleChunk: 'Hello',
titleTemplate: '%s',
htmlAttrs: {},
bodyAttrs: {},
meta: [
{ charset: 'utf-8' }
],
base: [],
link: [],
style: [],
script: [],
noscript: []
})
})
})

0 comments on commit ace5030

Please sign in to comment.