/ core Public
fix(runtime-core): allow spying on proxy methods #4216
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge.
Since Jest v26.6.1, the mock method changed (see this commit facebook/jest@30e8020) to rely on
Object.definePropertyin some cases.
This breaks spying on proxy's methods, because even if Jest is properly calling
Object.defineProperty, the cached value in the
getsection of the proxy is never updated, and the spy is in fact never used.
This is easily reproducible as vue-next already uses a version of jest with these changes.
This is blocking projects (like vue-test-utils-next and vue-cli) to update to recent Jest versions.
This commit adds a
definePropertymethod to the proxy handler, that properly updates the defined value in the cache.
Again, the fix is maybe too naive, and I'm happy to update the PR with a better solution.
edit: the same happens with Vitest