Skip to content

Commit

Permalink
feat: export hasMetaInfo helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
pimlie committed Mar 5, 2019
1 parent f597f61 commit 173b31d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/basic/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Vue from 'vue'
import VueMeta from 'vue-meta'
import * as VueMeta from 'vue-meta'

Vue.use(VueMeta)

Expand Down
14 changes: 8 additions & 6 deletions src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@ import createMixin from './shared/mixin'
import setOptions from './shared/options'
import { isUndefined } from './shared/typeof'
import $meta from './client/$meta'
export { hasMetaInfo } from './shared/hasMetaInfo'
import { hasMetaInfo } from './shared/hasMetaInfo'

/**
* Plugin install function.
* @param {Function} Vue - the Vue constructor.
*/
function VueMeta(Vue, options = {}) {
function install(Vue, options = {}) {
options = setOptions(options)

Vue.prototype.$meta = $meta(options)

Vue.mixin(createMixin(Vue, options))
}

VueMeta.version = version

// automatic install
if (!isUndefined(window) && !isUndefined(window.Vue)) {
/* istanbul ignore next */
Vue.use(VueMeta)
install(window.Vue)
}

export default VueMeta
export default {
version,
install,
hasMetaInfo
}
12 changes: 7 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ import { version } from '../package.json'
import createMixin from './shared/mixin'
import setOptions from './shared/options'
import $meta from './server/$meta'
export { hasMetaInfo } from './shared/hasMetaInfo'
import { hasMetaInfo } from './shared/hasMetaInfo'

/**
* Plugin install function.
* @param {Function} Vue - the Vue constructor.
*/
function VueMeta(Vue, options = {}) {
function install(Vue, options = {}) {
options = setOptions(options)

Vue.prototype.$meta = $meta(options)

Vue.mixin(createMixin(Vue, options))
}

VueMeta.version = version

export default VueMeta
export default {
version,
install,
hasMetaInfo
}
4 changes: 2 additions & 2 deletions test/plugin-server.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mount, defaultOptions, hasMetaInfo, VueMetaServerPlugin, loadVueMetaPlugin } from './utils'
import { mount, defaultOptions, VueMetaServerPlugin, loadVueMetaPlugin } from './utils'

jest.mock('../package.json', () => ({
version: 'test-version'
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('plugin', () => {

const { vm } = mount(Component, { localVue: Vue })

expect(hasMetaInfo(vm)).toBe(true)
expect(VueMetaServerPlugin.hasMetaInfo(vm)).toBe(true)
expect(warn).not.toHaveBeenCalled()

warn.mockRestore()
Expand Down
3 changes: 1 addition & 2 deletions test/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mount, createLocalVue } from '@vue/test-utils'
import { renderToString } from '@vue/server-test-utils'
import VueMetaBrowserPlugin from '../../src/browser'
import VueMetaServerPlugin, { hasMetaInfo } from '../../src'
import VueMetaServerPlugin from '../../src'

import {
keyName,
Expand All @@ -15,7 +15,6 @@ import {
export {
mount,
renderToString,
hasMetaInfo,
VueMetaBrowserPlugin,
VueMetaServerPlugin
}
Expand Down

0 comments on commit 173b31d

Please sign in to comment.