Skip to content

Commit

Permalink
fix(compat): do not overwrite globalProperties merge them instead
Browse files Browse the repository at this point in the history
* globalProperties might not be empty due to them being gathered
from Vue.prototype when using compat build
  • Loading branch information
xanf authored and cexbrayat committed Oct 2, 2022
1 parent 631e0a5 commit e754fd1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/mount.ts
Expand Up @@ -30,6 +30,7 @@ import {
import { MountingOptions, Slot } from './types'
import {
isFunctionalComponent,
isObject,
isObjectComponent,
mergeGlobalProperties
} from './utils'
Expand Down Expand Up @@ -474,7 +475,9 @@ export function mount(
keyof Omit<AppConfig, 'isNativeTag'>,
any
][]) {
app.config[k] = v
app.config[k] = isObject(app.config[k])
? Object.assign(app.config[k]!, v)
: v
}
}

Expand Down
18 changes: 17 additions & 1 deletion tests/features/compat.spec.ts
Expand Up @@ -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])(
Expand Down Expand Up @@ -213,4 +214,19 @@ describe('@vue/compat build', () => {
'<div class="foo" text="message" style="color: red;">message</div>'
)
})

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)
})
})

0 comments on commit e754fd1

Please sign in to comment.