Skip to content

Commit 73117f6

Browse files
authored
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.
1 parent 48f0d29 commit 73117f6

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

packages/runtime-core/__tests__/componentProps.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ describe('component props', () => {
295295
;(instance!.proxy as any).foo = 2
296296
}).toThrow(TypeError)
297297
expect(`Attempting to mutate prop "foo"`).toHaveBeenWarned()
298+
// should not throw when overriding properties other than props
299+
expect(() => {
300+
;(instance!.proxy as any).hasOwnProperty = () => {}
301+
}).not.toThrow(TypeError)
298302
})
299303

300304
test('merging props from mixins and extends', () => {

packages/runtime-core/src/componentPublicInstance.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
368368
setupState[key] = value
369369
} else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
370370
data[key] = value
371-
} else if (key in instance.props) {
371+
} else if (hasOwn(instance.props, key)) {
372372
__DEV__ &&
373373
warn(
374374
`Attempting to mutate prop "${key}". Props are readonly.`,

0 commit comments

Comments
 (0)