From ecd725dd584f18b1a4f3f3a65513e6c955ee2a24 Mon Sep 17 00:00:00 2001 From: pimlie Date: Tue, 11 Jun 2019 16:15:29 +0200 Subject: [PATCH] fix: $meta can be called server side before app is initiated --- src/server/$meta.js | 11 ----------- test/unit/plugin-server.test.js | 20 -------------------- 2 files changed, 31 deletions(-) diff --git a/src/server/$meta.js b/src/server/$meta.js index 6be46f7..42694a6 100644 --- a/src/server/$meta.js +++ b/src/server/$meta.js @@ -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), diff --git a/test/unit/plugin-server.test.js b/test/unit/plugin-server.test.js index 9ff4d4f..cf6cd9a 100644 --- a/test/unit/plugin-server.test.js +++ b/test/unit/plugin-server.test.js @@ -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))