Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): allow calling hasOwnProperty on proxy #4215

Closed
wants to merge 1 commit into from

Conversation

cexbrayat
Copy link
Member

It is currently not possible to call hasOwnProperty on the proxy instance,
which makes it impossible to spy with Jest, as Jest needs to call this method (see https://github.com/facebook/jest/blob/30e802036291f4c9c9fd4feef6faba485df54dd2/packages/jest-mock/src/index.ts#L986)

This commit fixes this by properly returning the hasOwnProperty method in the get section of the proxy.

There is currently a workaround in vue-test-utils-next that monkey patches the proxy to add the method (see https://github.com/vuejs/vue-test-utils-next/blob/23d3d3e1f4178a87de5023f5255e0623653affdc/src/mount.ts#L493-L495).
This is temporarily fine, but developers trying to create spies without using @vue/test-utils will run into the same issue.

The proposed fix is obviously very naive: the point was just to get the ball rolling 馃檪

It is currently not possible to call `hasOwnProperty` on the proxy instance,
which makes it impossible to spy with Jest, as Jest needs to call this method (see https://github.com/facebook/jest/blob/30e802036291f4c9c9fd4feef6faba485df54dd2/packages/jest-mock/src/index.ts#L986)

This commit fixes this by properly returning the `hasOwnProperty` method in the `get` section of the proxy.

There is currently a workaround in vue-test-utils-next that monkey patches the proxy to add the method (see https://github.com/vuejs/vue-test-utils-next/blob/23d3d3e1f4178a87de5023f5255e0623653affdc/src/mount.ts#L493-L495).
This is temporarily fine, but developers trying to create spies without using @vue/test-utils will run into the same issue.
@yyx990803
Copy link
Member

I feel this is something that should be fixed in Jest - its usage of hasOwnProperty would break on any object that has null as prototype, or any other proxies that filters allowed keys.

Instead it should use Object.prototype.hasOwnProperty.call(...).

@cexbrayat
Copy link
Member Author

Sounds good. I opened jestjs/jest#11721 in Jest itself
Let's see if that lands

@cexbrayat
Copy link
Member Author

The PR landed in Jest, and was released as v27.1

PR #4472 updates vue-next to use this new version which fixes the issue, making this PR obsolete

@cexbrayat cexbrayat closed this Aug 30, 2021
@cexbrayat cexbrayat deleted the fix/has-own-property branch August 30, 2021 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants