-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
fix(mock): allow to mock methods in getters #10156
Conversation
Hi @SomaticIT! Thank you for your pull request and welcome to our community.We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
Don't we support this already via the third option? https://jestjs.io/docs/en/jest-object#jestspyonobject-methodname-accesstype |
@SomaticIT ping 🙂 |
The third option, allows to replace the In my case, we want to change the function which is returned by the So the difference:
This fix allows to easily handle this case with no overhead for the user. |
Aha! Yeah, I think this makes sense, then. Mind giving this a quick rebase (or merge in master)? |
59d3811
to
06e596c
Compare
06e596c
to
0531a25
Compare
@SimenB |
Thanks! |
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
In TypeScript
3.9.x
, module "re-export" is done using readonly accessor.It breaks all tests written using
jest.spyOn
mocks.A solution is to automatically mock methods that are wrapped in getters.
Test plan
If
module-a
was built using TypeScript< 3.9
, this will work.If
module-a
was built using TypeScript>= 3.9
, this will throw with errorTypeError: Cannot set property query of #<Object> which has only a getter
.