2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-23 05:50:34 +03:00

fix: use single object prop on

feat: provide hasMetaInfo export for other libraries to check if metaInfo has been defined

chore: deprecate _hasMetaInfo
This commit is contained in:
pimlie
2019-02-23 13:49:37 +01:00
parent 5935cf32cc
commit 9c80dab7b2
9 changed files with 83 additions and 20 deletions
+6 -6
View File
@@ -72,8 +72,8 @@ describe('plugin', () => {
})
// no batchUpdate on initialization
expect(wrapper.vm.$root._vueMetaInitialized).toBe(false)
expect(wrapper.vm.$root._vueMetaPaused).toBeFalsy()
expect(wrapper.vm.$root._vueMeta.initialized).toBe(false)
expect(wrapper.vm.$root._vueMeta.paused).toBeFalsy()
expect(triggerUpdateSpy).toHaveBeenCalledTimes(1)
expect(batchUpdateSpy).not.toHaveBeenCalled()
jest.clearAllMocks()
@@ -83,8 +83,8 @@ describe('plugin', () => {
wrapper.setProps({ title })
// batchUpdate on normal update
expect(wrapper.vm.$root._vueMetaInitialized).toBe(true)
expect(wrapper.vm.$root._vueMetaPaused).toBeFalsy()
expect(wrapper.vm.$root._vueMeta.initialized).toBe(true)
expect(wrapper.vm.$root._vueMeta.paused).toBeFalsy()
expect(triggerUpdateSpy).toHaveBeenCalledTimes(1)
expect(batchUpdateSpy).toHaveBeenCalledTimes(1)
jest.clearAllMocks()
@@ -94,8 +94,8 @@ describe('plugin', () => {
wrapper.setProps({ title })
// no batchUpdate when paused
expect(wrapper.vm.$root._vueMetaInitialized).toBe(true)
expect(wrapper.vm.$root._vueMetaPaused).toBe(true)
expect(wrapper.vm.$root._vueMeta.initialized).toBe(true)
expect(wrapper.vm.$root._vueMeta.paused).toBe(true)
expect(triggerUpdateSpy).toHaveBeenCalledTimes(1)
expect(batchUpdateSpy).not.toHaveBeenCalled()
jest.clearAllMocks()
+41 -1
View File
@@ -1,4 +1,4 @@
import { mount, defaultOptions, VueMetaServerPlugin, loadVueMetaPlugin } from './utils'
import { mount, defaultOptions, hasMetaInfo, VueMetaServerPlugin, loadVueMetaPlugin } from './utils'
jest.mock('../package.json', () => ({
version: 'test-version'
@@ -7,6 +7,7 @@ jest.mock('../package.json', () => ({
describe('plugin', () => {
let Vue
beforeEach(() => jest.clearAllMocks())
beforeAll(() => (Vue = loadVueMetaPlugin()))
test('is loaded', () => {
@@ -29,4 +30,43 @@ describe('plugin', () => {
test('plugin sets package version', () => {
expect(VueMetaServerPlugin.version).toBe('test-version')
})
test('prints deprecation warning once when using _hasMetaInfo', () => {
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {})
const Component = Vue.component('test-component', {
template: '<div>Test</div>',
[defaultOptions.keyName]: {
title: 'Hello World'
}
})
Vue.config.devtools = true
const { vm } = mount(Component, { localVue: Vue })
expect(vm._hasMetaInfo).toBe(true)
expect(warn).toHaveBeenCalledTimes(1)
expect(vm._hasMetaInfo).toBe(true)
expect(warn).toHaveBeenCalledTimes(1)
warn.mockRestore()
})
test('can use hasMetaInfo export', () => {
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {})
const Component = Vue.component('test-component', {
template: '<div>Test</div>',
[defaultOptions.keyName]: {
title: 'Hello World'
}
})
const { vm } = mount(Component, { localVue: Vue })
expect(hasMetaInfo(vm)).toBe(true)
expect(warn).not.toHaveBeenCalled()
warn.mockRestore()
})
})
+2 -1
View File
@@ -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 from '../../src'
import VueMetaServerPlugin, { hasMetaInfo } from '../../src'
import {
keyName,
@@ -15,6 +15,7 @@ import {
export {
mount,
renderToString,
hasMetaInfo,
VueMetaBrowserPlugin,
VueMetaServerPlugin
}