Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compat): do not overwrite globalProperties merge them instead #1788

Merged
merged 1 commit into from Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
})
})