-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
fix(jest-runtime): Guard '_isMockFunction' access with 'in' #14188
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Deploy Preview for jestjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
fc3d89e to
2c9e9c5
Compare
SimenB
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clean fix, thanks!
I'd be interested in the WeakSet change you mention if you ever find the time! 😀
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
This fixes an issue in
jest-runtimewhen attempting to reset global mocks. Whenjestis running inside of VS Code to test a VS Code extension, it attempts to read_isMockFunctionfrom aProxythat happens to throw in itsgethandler when you unconditionally read a property that does not exist. Prefixing this condition with a test forinavoids evaluating thegethook.NOTE: While this does resolve this specific case, it's still possible a global could be a
Proxythat even throws onin, though that would generally be a bad practice. It would be much safer to replace_isMockFunctionentirely with aWeakSetthat does not interact with aProxyat all, but that is a far more comprehensive change than I'm willing to commit to at this point.Test plan
I've tested this locally through the use of a custom
JestEnvironment, such as this one:I've added something similar to the above as a test in this PR.
Fixes #14095