From d1e95bcc84e08e97d0b362463748c4dfa3bba8e6 Mon Sep 17 00:00:00 2001 From: cexbrayat Date: Tue, 26 Jan 2021 18:03:36 +0100 Subject: [PATCH] fix(runtime-core): allow overriding properties other than props 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. --- packages/runtime-core/__tests__/componentProps.spec.ts | 4 ++++ packages/runtime-core/src/componentPublicInstance.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/__tests__/componentProps.spec.ts b/packages/runtime-core/__tests__/componentProps.spec.ts index f75d3c2ebbd..83400cf2a05 100644 --- a/packages/runtime-core/__tests__/componentProps.spec.ts +++ b/packages/runtime-core/__tests__/componentProps.spec.ts @@ -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', () => { diff --git a/packages/runtime-core/src/componentPublicInstance.ts b/packages/runtime-core/src/componentPublicInstance.ts index 1e62f8b16c5..3684cf78582 100644 --- a/packages/runtime-core/src/componentPublicInstance.ts +++ b/packages/runtime-core/src/componentPublicInstance.ts @@ -368,7 +368,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler = { 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.`,