From 8f39c97128328b9092689b7f65ecb05d6e03c478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Mon, 14 Nov 2016 20:40:10 +0100 Subject: [PATCH 1/2] Fix: merge array if vmid is undefined --- examples/vuex-async/App.vue | 2 +- examples/webpack.config.babel.js | 6 +++--- src/shared/getMetaInfo.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/vuex-async/App.vue b/examples/vuex-async/App.vue index 0a981c58..8e9d1c6c 100644 --- a/examples/vuex-async/App.vue +++ b/examples/vuex-async/App.vue @@ -10,7 +10,7 @@ export default { metaInfo: { meta: [ - { vmid: 'charset', charset: 'utf-8' } + { charset: 'utf-8' } ] } } diff --git a/examples/webpack.config.babel.js b/examples/webpack.config.babel.js index 624736c5..a7ca4524 100644 --- a/examples/webpack.config.babel.js +++ b/examples/webpack.config.babel.js @@ -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' } ] }, diff --git a/src/shared/getMetaInfo.js b/src/shared/getMetaInfo.js index 804e098a..87d13562 100644 --- a/src/shared/getMetaInfo.js +++ b/src/shared/getMetaInfo.js @@ -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 } From 488d6d1dcad93f278d041160022c70915f16e65c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Mon, 14 Nov 2016 20:52:42 +0100 Subject: [PATCH 2/2] Add options for testing getMetaInfo --- test/getMetaInfo.spec.js | 42 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/test/getMetaInfo.spec.js b/test/getMetaInfo.spec.js index 9bd7e0eb..e2402fd7 100644 --- a/test/getMetaInfo.spec.js +++ b/test/getMetaInfo.spec.js @@ -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') @@ -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: [] + }) + }) })