diff --git a/src/shared/plugin.js b/src/shared/plugin.js index a493dcc..1649348 100644 --- a/src/shared/plugin.js +++ b/src/shared/plugin.js @@ -87,7 +87,7 @@ export default function VueMeta (Vue, options = {}) { if (this._hasMetaInfo) { // Wait that element is hidden before refreshing meta tags (to support animations) const interval = setInterval(() => { - if (this.$el.offsetParent !== null) return + if (this.$el && this.$el.offsetParent !== null) return clearInterval(interval) batchID = batchUpdate(batchID, () => this.$meta().refresh()) }, 50) diff --git a/test/plugin.spec.js b/test/plugin.spec.js new file mode 100644 index 0000000..aa8d080 --- /dev/null +++ b/test/plugin.spec.js @@ -0,0 +1,33 @@ +import Vue from 'vue' +import VueMeta from '../src/shared/plugin' +import { + VUE_META_KEY_NAME, + VUE_META_ATTRIBUTE, + VUE_META_SERVER_RENDERED_ATTRIBUTE, + VUE_META_TAG_LIST_ID_KEY_NAME +} from '../src/shared/constants' + +describe('plugin', () => { + Vue.use(VueMeta, { + keyName: VUE_META_KEY_NAME, + attribute: VUE_META_ATTRIBUTE, + ssrAttribute: VUE_META_SERVER_RENDERED_ATTRIBUTE, + tagIDKeyName: VUE_META_TAG_LIST_ID_KEY_NAME + }) + + it('adds $meta() to Vue prototype', () => { + const instance = new Vue() + expect(instance.$meta).to.be.a('function') + }) + + it('components have _hasMetaInfo set to true', () => { + const Component = Vue.component('test-component', { + template: '
Test
', + [VUE_META_KEY_NAME]: { + title: 'helloworld' + } + }) + const vm = new Vue(Component).$mount() + expect(vm._hasMetaInfo).to.equal(true) + }) +})