wip: make singleton mutations affect all app instances

This commit is contained in:
Evan You
2021-05-05 17:56:09 -04:00
parent 61edb700d7
commit f2a5a3ee55
5 changed files with 107 additions and 56 deletions

View File

@@ -6,6 +6,8 @@ import {
deprecationData,
toggleDeprecationWarning
} from '../../runtime-core/src/compat/compatConfig'
import { singletonApp } from '../../runtime-core/src/compat/global'
import { createApp } from '../src/esm-index'
beforeEach(() => {
toggleDeprecationWarning(false)
@@ -280,6 +282,15 @@ describe('GLOBAL_PROTOTYPE', () => {
const plain = new Vue() as any
expect(plain.$test).toBeUndefined()
})
test('should affect apps created via createApp()', () => {
Vue.prototype.$test = 1
const vm = createApp({
template: 'foo'
}).mount(document.createElement('div')) as any
expect(vm.$test).toBe(1)
delete Vue.prototype.$test
})
})
describe('GLOBAL_SET/DELETE', () => {
@@ -381,3 +392,12 @@ describe('GLOBAL_PRIVATE_UTIL', () => {
expect(n).toBe(2)
})
})
test('global asset registration should affect apps created via createApp', () => {
Vue.component('foo', { template: 'foo' })
const vm = createApp({
template: '<foo/>'
}).mount(document.createElement('div')) as any
expect(vm.$el.textContent).toBe('foo')
delete singletonApp._context.components.foo
})

View File

@@ -1,5 +1,6 @@
import Vue from '@vue/compat'
import { toggleDeprecationWarning } from '../../runtime-core/src/compat/compatConfig'
import { createApp } from '../src/esm-index'
import { triggerEvent } from './utils'
beforeEach(() => {
@@ -64,3 +65,12 @@ test('GLOBAL_IGNORED_ELEMENTS', () => {
})
expect(el.innerHTML).toBe(`<v-foo></v-foo><foo></foo>`)
})
test('singleton config should affect apps created with createApp()', () => {
Vue.config.ignoredElements = [/^v-/, 'foo']
const el = document.createElement('div')
createApp({
template: `<v-foo/><foo/>`
}).mount(el)
expect(el.innerHTML).toBe(`<v-foo></v-foo><foo></foo>`)
})