feat(runtime-core): support app.config.globalProperties

per https://github.com/vuejs/rfcs/pull/117/
This commit is contained in:
Evan You
2020-03-25 09:28:37 -04:00
parent 394fd4c6aa
commit 27873dbe1c
4 changed files with 53 additions and 26 deletions

View File

@@ -440,4 +440,38 @@ describe('api: createApp', () => {
).toHaveBeenWarned()
})
})
test('config.optionMergeStrategies', () => {
let merged: string
const App = defineComponent({
render() {},
mixins: [{ foo: 'mixin' }],
extends: { foo: 'extends' },
foo: 'local',
beforeCreate() {
merged = this.$options.foo
}
})
const app = createApp(App)
app.mixin({
foo: 'global'
})
app.config.optionMergeStrategies.foo = (a, b) => (a ? `${a},` : ``) + b
app.mount(nodeOps.createElement('div'))
expect(merged!).toBe('global,extends,mixin,local')
})
test('config.globalProperties', () => {
const app = createApp({
render() {
return this.foo
}
})
app.config.globalProperties.foo = 'hello'
const root = nodeOps.createElement('div')
app.mount(root)
expect(serializeInner(root)).toBe('hello')
})
})

View File

@@ -563,28 +563,6 @@ describe('api: options', () => {
expect(serializeInner(root)).toBe(`<div>1,1,3</div>`)
})
test('optionMergeStrategies', () => {
let merged: string
const App = defineComponent({
render() {},
mixins: [{ foo: 'mixin' }],
extends: { foo: 'extends' },
foo: 'local',
beforeCreate() {
merged = this.$options.foo
}
})
const app = createApp(App)
app.mixin({
foo: 'global'
})
app.config.optionMergeStrategies.foo = (a, b) => (a ? `${a},` : ``) + b
app.mount(nodeOps.createElement('div'))
expect(merged!).toBe('global,extends,mixin,local')
})
describe('warnings', () => {
mockWarn()