-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
fix(jest-runtime): Guard '_isMockFunction' access with 'in' #14188
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
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-runtime
when attempting to reset global mocks. Whenjest
is running inside of VS Code to test a VS Code extension, it attempts to read_isMockFunction
from aProxy
that happens to throw in itsget
handler when you unconditionally read a property that does not exist. Prefixing this condition with a test forin
avoids evaluating theget
hook.NOTE: While this does resolve this specific case, it's still possible a global could be a
Proxy
that even throws onin
, though that would generally be a bad practice. It would be much safer to replace_isMockFunction
entirely with aWeakSet
that does not interact with aProxy
at 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