Skip to content

Commit ecd725d

Browse files
committed
fix: $meta can be called server side before app is initiated
1 parent 02237e0 commit ecd725d

File tree

2 files changed

+0
-31
lines changed

2 files changed

+0
-31
lines changed

src/server/$meta.js

-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { showWarningNotSupported } from '../shared/constants'
21
import { getOptions } from '../shared/options'
32
import { pause, resume } from '../shared/pausing'
43
import refresh from '../client/refresh'
@@ -14,16 +13,6 @@ export default function _$meta(options = {}) {
1413
* @return {Object} - injector
1514
*/
1615
return function $meta() {
17-
if (!this.$root._vueMeta) {
18-
return {
19-
getOptions: showWarningNotSupported,
20-
refresh: showWarningNotSupported,
21-
inject: showWarningNotSupported,
22-
pause: showWarningNotSupported,
23-
resume: showWarningNotSupported
24-
}
25-
}
26-
2716
return {
2817
getOptions: () => getOptions(options),
2918
refresh: _refresh.bind(this),

test/unit/plugin-server.test.js

-20
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,6 @@ describe('plugin', () => {
1111
beforeEach(() => jest.clearAllMocks())
1212
beforeAll(() => (Vue = loadVueMetaPlugin()))
1313

14-
test('not loaded when no metaInfo defined', () => {
15-
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {})
16-
17-
const instance = new Vue()
18-
expect(instance.$meta).toEqual(expect.any(Function))
19-
20-
expect(instance.$meta().inject).toEqual(expect.any(Function))
21-
expect(instance.$meta().refresh).toEqual(expect.any(Function))
22-
expect(instance.$meta().getOptions).toEqual(expect.any(Function))
23-
24-
expect(instance.$meta().inject()).not.toBeDefined()
25-
expect(warn).toHaveBeenCalledTimes(1)
26-
expect(instance.$meta().refresh()).not.toBeDefined()
27-
expect(warn).toHaveBeenCalledTimes(2)
28-
29-
instance.$meta().getOptions()
30-
expect(warn).toHaveBeenCalledTimes(3)
31-
warn.mockRestore()
32-
})
33-
3414
test('is loaded', () => {
3515
const instance = new Vue({ metaInfo: {} })
3616
expect(instance.$meta).toEqual(expect.any(Function))

0 commit comments

Comments
 (0)