From d4ef6288ed13649a112bf72df0d07ff78b907785 Mon Sep 17 00:00:00 2001 From: Illya Klymov Date: Sun, 2 Oct 2022 21:17:05 +0300 Subject: [PATCH] fix(compat): do not overwrite globalProperties merge them instead * globalProperties might not be empty due to them being gathered from Vue.prototype when using compat build --- src/mount.ts | 5 ++++- tests/features/compat.spec.ts | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/mount.ts b/src/mount.ts index 36651e962..129ef1d38 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -30,6 +30,7 @@ import { import { MountingOptions, Slot } from './types' import { isFunctionalComponent, + isObject, isObjectComponent, mergeGlobalProperties } from './utils' @@ -474,7 +475,9 @@ export function mount( keyof Omit, any ][]) { - app.config[k] = v + app.config[k] = isObject(app.config[k]) + ? Object.assign(app.config[k]!, v) + : v } } diff --git a/tests/features/compat.spec.ts b/tests/features/compat.spec.ts index 92bf28ddf..34c337885 100644 --- a/tests/features/compat.spec.ts +++ b/tests/features/compat.spec.ts @@ -3,8 +3,9 @@ import * as mockVue from '@vue/compat' import { mount } from '../../src' vi.mock('vue', () => mockVue) - const { configureCompat, extend, defineComponent, h } = mockVue +// @ts-expect-error @vue/compat does not expose default export in types +const Vue = mockVue.default describe('@vue/compat build', () => { describe.each(['suppress-warning', false])( @@ -213,4 +214,19 @@ describe('@vue/compat build', () => { '
message
' ) }) + + it('does not erase globalProperties added by messing with Vue.prototype', () => { + configureCompat({ + MODE: 3, + GLOBAL_PROTOTYPE: 'suppress-warning' + }) + + Vue.prototype.$test = 1 + + const Component = { template: 'hello ' } + const wrapper = mount(Component) + + // @ts-expect-error $test "magically" appears from "Vue.prototype" in compat build + expect(wrapper.vm.$test).toBe(1) + }) })