Skip to content

Commit

Permalink
fix(runtime-core): allow overriding properties other than props (#3105)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cexbrayat committed Feb 5, 2021
1 parent 48f0d29 commit 73117f6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/runtime-core/__tests__/componentProps.spec.ts
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/componentPublicInstance.ts
Expand Up @@ -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.`,
Expand Down

0 comments on commit 73117f6

Please sign in to comment.