fix(runtime-core): fix globalProperties in check on instance render proxy
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
import { h, render, getCurrentInstance, nodeOps } from '@vue/runtime-test'
|
||||
import {
|
||||
h,
|
||||
render,
|
||||
getCurrentInstance,
|
||||
nodeOps,
|
||||
createApp
|
||||
} from '@vue/runtime-test'
|
||||
import { mockWarn } from '@vue/shared'
|
||||
import { ComponentInternalInstance } from '../src/component'
|
||||
|
||||
@@ -137,6 +143,33 @@ describe('component: proxy', () => {
|
||||
expect(instance!.sink.foo).toBe(1)
|
||||
})
|
||||
|
||||
test('globalProperties', () => {
|
||||
let instance: ComponentInternalInstance
|
||||
let instanceProxy: any
|
||||
const Comp = {
|
||||
setup() {
|
||||
return () => null
|
||||
},
|
||||
mounted() {
|
||||
instance = getCurrentInstance()!
|
||||
instanceProxy = this
|
||||
}
|
||||
}
|
||||
|
||||
const app = createApp(Comp)
|
||||
app.config.globalProperties.foo = 1
|
||||
app.mount(nodeOps.createElement('div'))
|
||||
|
||||
expect(instanceProxy.foo).toBe(1)
|
||||
|
||||
// set should overwrite globalProperties with local
|
||||
instanceProxy.foo = 2
|
||||
expect(instanceProxy.foo).toBe(2)
|
||||
expect(instance!.sink.foo).toBe(2)
|
||||
// should not affect global
|
||||
expect(app.config.globalProperties.foo).toBe(1)
|
||||
})
|
||||
|
||||
test('has check', () => {
|
||||
let instanceProxy: any
|
||||
const Comp = {
|
||||
@@ -158,7 +191,11 @@ describe('component: proxy', () => {
|
||||
instanceProxy = this
|
||||
}
|
||||
}
|
||||
render(h(Comp, { msg: 'hello' }), nodeOps.createElement('div'))
|
||||
|
||||
const app = createApp(Comp, { msg: 'hello' })
|
||||
app.config.globalProperties.global = 1
|
||||
|
||||
app.mount(nodeOps.createElement('div'))
|
||||
|
||||
// props
|
||||
expect('msg' in instanceProxy).toBe(true)
|
||||
@@ -168,6 +205,8 @@ describe('component: proxy', () => {
|
||||
expect('bar' in instanceProxy).toBe(true)
|
||||
// public properties
|
||||
expect('$el' in instanceProxy).toBe(true)
|
||||
// global properties
|
||||
expect('global' in instanceProxy).toBe(true)
|
||||
|
||||
// non-existent
|
||||
expect('$foobar' in instanceProxy).toBe(false)
|
||||
@@ -178,6 +217,7 @@ describe('component: proxy', () => {
|
||||
expect('baz' in instanceProxy).toBe(true)
|
||||
|
||||
// dev mode ownKeys check for console inspection
|
||||
// should only expose own keys
|
||||
expect(Object.keys(instanceProxy)).toMatchObject([
|
||||
'msg',
|
||||
'bar',
|
||||
|
||||
Reference in New Issue
Block a user