2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-17 22:20:33 +03:00

chore: add separate tests for server and browser plugin

This commit is contained in:
pimlie
2019-02-11 12:40:00 +01:00
parent 02e4094a35
commit 93fb27a694
3 changed files with 17 additions and 36 deletions
+7
View File
@@ -1,6 +1,7 @@
import { version } from '../package.json'
import createMixin from './shared/mixin'
import setOptions from './shared/options'
import { isUndefined } from './shared/typeof'
import $meta from './client/$meta'
/**
@@ -17,4 +18,10 @@ function VueMeta(Vue, options = {}) {
VueMeta.version = version
// automatic install
if (!isUndefined(window) && !isUndefined(window.Vue)) {
/* istanbul ignore next */
Vue.use(VueMeta)
}
export default VueMeta
-32
View File
@@ -1,32 +0,0 @@
import { mount, defaultOptions, VueMetaPlugin, loadVueMetaPlugin } from './utils'
jest.mock('../package.json', () => ({
version: 'test-version'
}))
describe('plugin', () => {
let Vue
beforeAll(() => (Vue = loadVueMetaPlugin()))
test('is loaded', () => {
const instance = new Vue()
expect(instance.$meta).toEqual(expect.any(Function))
})
test('component has _hasMetaInfo set to true', () => {
const Component = Vue.component('test-component', {
template: '<div>Test</div>',
[defaultOptions.keyName]: {
title: 'Hello World'
}
})
const { vm } = mount(Component, { localVue: Vue })
expect(vm._hasMetaInfo).toBe(true)
})
test('plugin sets package version', () => {
expect(VueMetaPlugin.version).toBe('test-version')
})
})
+10 -4
View File
@@ -1,6 +1,7 @@
import { mount, createLocalVue } from '@vue/test-utils'
import { renderToString } from '@vue/server-test-utils'
import VueMetaPlugin from '../../src'
import VueMetaBrowserPlugin from '../../src/browser'
import VueMetaServerPlugin from '../../src'
import {
keyName,
@@ -14,7 +15,8 @@ import {
export {
mount,
renderToString,
VueMetaPlugin
VueMetaBrowserPlugin,
VueMetaServerPlugin
}
export const defaultOptions = {
@@ -30,8 +32,12 @@ export function getVue() {
return createLocalVue()
}
export function loadVueMetaPlugin(options, localVue = getVue()) {
localVue.use(VueMetaPlugin, Object.assign({}, defaultOptions, options))
export function loadVueMetaPlugin(browser, options, localVue = getVue()) {
if (browser) {
localVue.use(VueMetaBrowserPlugin, Object.assign({}, defaultOptions, options))
} else {
localVue.use(VueMetaServerPlugin, Object.assign({}, defaultOptions, options))
}
return localVue
}