-
-
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
spyOn getter only works for static getters and not for instance getters #9675
Comments
I have this issue as well. The workaround works but it would nice if spyOn also worked for instance properties. |
dang! it's at least nice when the last comment is less than 2 weeks ago. thanks for the workaround. seems a bit janky though! |
any progress on it? This workaround seems not to work for me |
Quite unpleasant bug when working with Mobx and TypeScript. I'm currently working around this by setting the property directly and ignoring the typescript error for now:
|
This is still broken in Jest@28.1.3, though my issue is with automocked classes not having any getter/setter mocks at all. opened a new issue #13140 |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
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
If I try to spy on a getter with
spyOn(instance,'foo','get').and.returnValue(false);
I get the error
To Reproduce
Here are two examples, one for a static property and one for an instance property. The first test works. The second fails.
My babel-setting inside package.json are:
Expected behavior
The instance property "foo" should be found and the second test should work, too.
envinfo
related
#8137
#5746
https://jestjs.io/docs/en/jest-object.html#jestspyonobject-methodname-accesstype
Workaround
Inststead of
spyOn(instance,'foo','get').and.returnValue(false);
I am able to use
Object.defineProperty(instance, 'foo', { get(){ return false; } });
The text was updated successfully, but these errors were encountered: