mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-18 02:30:33 +03:00
fix: $meta can be called server side before app is initiated
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { showWarningNotSupported } from '../shared/constants'
|
||||
import { getOptions } from '../shared/options'
|
||||
import { pause, resume } from '../shared/pausing'
|
||||
import refresh from '../client/refresh'
|
||||
@@ -14,16 +13,6 @@ export default function _$meta(options = {}) {
|
||||
* @return {Object} - injector
|
||||
*/
|
||||
return function $meta() {
|
||||
if (!this.$root._vueMeta) {
|
||||
return {
|
||||
getOptions: showWarningNotSupported,
|
||||
refresh: showWarningNotSupported,
|
||||
inject: showWarningNotSupported,
|
||||
pause: showWarningNotSupported,
|
||||
resume: showWarningNotSupported
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
getOptions: () => getOptions(options),
|
||||
refresh: _refresh.bind(this),
|
||||
|
||||
@@ -11,26 +11,6 @@ describe('plugin', () => {
|
||||
beforeEach(() => jest.clearAllMocks())
|
||||
beforeAll(() => (Vue = loadVueMetaPlugin()))
|
||||
|
||||
test('not loaded when no metaInfo defined', () => {
|
||||
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {})
|
||||
|
||||
const instance = new Vue()
|
||||
expect(instance.$meta).toEqual(expect.any(Function))
|
||||
|
||||
expect(instance.$meta().inject).toEqual(expect.any(Function))
|
||||
expect(instance.$meta().refresh).toEqual(expect.any(Function))
|
||||
expect(instance.$meta().getOptions).toEqual(expect.any(Function))
|
||||
|
||||
expect(instance.$meta().inject()).not.toBeDefined()
|
||||
expect(warn).toHaveBeenCalledTimes(1)
|
||||
expect(instance.$meta().refresh()).not.toBeDefined()
|
||||
expect(warn).toHaveBeenCalledTimes(2)
|
||||
|
||||
instance.$meta().getOptions()
|
||||
expect(warn).toHaveBeenCalledTimes(3)
|
||||
warn.mockRestore()
|
||||
})
|
||||
|
||||
test('is loaded', () => {
|
||||
const instance = new Vue({ metaInfo: {} })
|
||||
expect(instance.$meta).toEqual(expect.any(Function))
|
||||
|
||||
Reference in New Issue
Block a user