mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-24 23:40:34 +03:00
chore: add separate tests for server and browser plugin
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { version } from '../package.json'
|
import { version } from '../package.json'
|
||||||
import createMixin from './shared/mixin'
|
import createMixin from './shared/mixin'
|
||||||
import setOptions from './shared/options'
|
import setOptions from './shared/options'
|
||||||
|
import { isUndefined } from './shared/typeof'
|
||||||
import $meta from './client/$meta'
|
import $meta from './client/$meta'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,4 +18,10 @@ function VueMeta(Vue, options = {}) {
|
|||||||
|
|
||||||
VueMeta.version = version
|
VueMeta.version = version
|
||||||
|
|
||||||
|
// automatic install
|
||||||
|
if (!isUndefined(window) && !isUndefined(window.Vue)) {
|
||||||
|
/* istanbul ignore next */
|
||||||
|
Vue.use(VueMeta)
|
||||||
|
}
|
||||||
|
|
||||||
export default VueMeta
|
export default VueMeta
|
||||||
|
|||||||
@@ -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
@@ -1,6 +1,7 @@
|
|||||||
import { mount, createLocalVue } from '@vue/test-utils'
|
import { mount, createLocalVue } from '@vue/test-utils'
|
||||||
import { renderToString } from '@vue/server-test-utils'
|
import { renderToString } from '@vue/server-test-utils'
|
||||||
import VueMetaPlugin from '../../src'
|
import VueMetaBrowserPlugin from '../../src/browser'
|
||||||
|
import VueMetaServerPlugin from '../../src'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
keyName,
|
keyName,
|
||||||
@@ -14,7 +15,8 @@ import {
|
|||||||
export {
|
export {
|
||||||
mount,
|
mount,
|
||||||
renderToString,
|
renderToString,
|
||||||
VueMetaPlugin
|
VueMetaBrowserPlugin,
|
||||||
|
VueMetaServerPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultOptions = {
|
export const defaultOptions = {
|
||||||
@@ -30,8 +32,12 @@ export function getVue() {
|
|||||||
return createLocalVue()
|
return createLocalVue()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadVueMetaPlugin(options, localVue = getVue()) {
|
export function loadVueMetaPlugin(browser, options, localVue = getVue()) {
|
||||||
localVue.use(VueMetaPlugin, Object.assign({}, defaultOptions, options))
|
if (browser) {
|
||||||
|
localVue.use(VueMetaBrowserPlugin, Object.assign({}, defaultOptions, options))
|
||||||
|
} else {
|
||||||
|
localVue.use(VueMetaServerPlugin, Object.assign({}, defaultOptions, options))
|
||||||
|
}
|
||||||
|
|
||||||
return localVue
|
return localVue
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user