]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): allow overriding properties other than props (#3105)
authorCédric Exbrayat <cexbrayat@users.noreply.github.com>
Fri, 5 Feb 2021 18:59:46 +0000 (19:59 +0100)
committerGitHub <noreply@github.com>
Fri, 5 Feb 2021 18:59:46 +0000 (19:59 +0100)
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
packages/runtime-core/src/componentPublicInstance.ts

index 2c072d45aae9eabf39e824c0cc70b5d974303e92..f89607c57e0dbe157bcf6a1af97b55c716bb58a4 100644 (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', () => {
index 0269fdf66dbb7389614e59e2bd60015dfa4cb31b..ba7eda893b168bd511a135e7688f38ab2727fe8d 100644 (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.`,