-
-
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
jest.resetModules() can fail when using identity-obj-proxy #7009
Comments
Interesting! We might want to consider som I've thought that I want to move all properties we attach to a mock behind a symbol anyways, but it's pretty breaking. @thymikee @rickhanlonii thoughts? |
Can the |
for sure. PR welcome 🙂 |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🐛 Bug Report
jest.resetModules() iterates over the global object and checks if any properties are mocks by evaluating if
globalMock._isMockFunction
is truthy for each property on the global. (https://github.com/facebook/jest/blob/949701376f1af75befd1a759aff5ac8080fb33af/packages/jest-runtime/src/index.js#L433)If using
identity-obj-proxy
to mock a property on the global object anywhere in the test setup, jest.resetModules will break.identity-obj-proxy
is a proxy that returns the key as the value for any attemps to index the object (https://github.com/keyanzhang/identity-obj-proxy/blob/master/src/index.js#L18) which means the value of_isMockFunction
will be the string_isMockFunction
which is truthy, and the value ofmockClear
will be the stringmockClear
which is not a function, ergo the errorTypeError: globalMock.mockClear is not a function
.To Reproduce
Steps to reproduce the behavior:
identity-obj-proxy
Expected behavior
Test should pass, correct mocks should be cleared
Link to repl or repo (highly encouraged)
https://repl.it/@danrr/SuperNegligibleGeeklog
Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: