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:
@@ -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
|
||||
|
||||
@@ -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 { 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user