fix(runtime-core): allow overriding properties other than props (#3105)

This is useful for testing, as Jest can't spy on an object without `hasOwnProperty`.
VTU can add it, but this commit is needed first.
This commit is contained in:
Cédric Exbrayat 2021-02-05 19:59:46 +01:00 committed by GitHub
parent 48f0d2944f
commit 73117f6b5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -295,6 +295,10 @@ describe('component props', () => {
;(instance!.proxy as any).foo = 2
}).toThrow(TypeError)
expect(`Attempting to mutate prop "foo"`).toHaveBeenWarned()
// should not throw when overriding properties other than props
expect(() => {
;(instance!.proxy as any).hasOwnProperty = () => {}
}).not.toThrow(TypeError)
})
test('merging props from mixins and extends', () => {

View File

@ -368,7 +368,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
setupState[key] = value
} else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
data[key] = value
} else if (key in instance.props) {
} else if (hasOwn(instance.props, key)) {
__DEV__ &&
warn(
`Attempting to mutate prop "${key}". Props are readonly.`,