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
Implement spies for get/set functions on accessor properties #943
Comments
+1 |
I can see that being useful. I don't think we want to add that complexity to the existing |
+1 |
+1 |
11 similar comments
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
I think at this point the +1s are crowding out any actual discussion that might happen here; please show your enthusiasm by subscribing yourself to the issue or adding a 👍 reaction with GitHub's new "reaction" feature so that everybody doesn't continue to get notifications for each new +1. Or, better yet, attach a pull request 😄 |
+1 |
@slackersoft We now have #1008 and #1203 able to be merged. Is there a timeline for this feature? |
Any guidance on when this will make it into a release? |
+1 |
1 similar comment
+1 |
@elwynelwyn @joshfermin @fimius23 I know this is late so you may know already, but this is available in 2.6 (#1203 (comment)) with docs at https://jasmine.github.io/api/edge/global.html#spyOnProperty |
I realise I am late to the game here, but does anybody know of a similar function call for jest? Wanting to test a getter in that also, but this addition is just jasmine.. |
@pauljeffreys you should probable ask the Jest folks. (https://github.com/facebook/jest) I'm not totally sure it's even still built on top of Jasmine in a way that would allow them to incorporate the work done here. |
@pauljeffreys @slackersoft see my PR at jestjs/jest#5107 |
I think it would be useful to extend
spyOn
(or add another method, likespyOnGetter
) to spy on the getter or setter function of an accessor property. Currently there is no way to spy on the followingget
functions, because Jasmine currently can only spy on functions that are properties, and not on functions that areset
/get
accessor functions of a property:It seems like the core functionality could be implemented using
defineProperty
to rewrite the property with a spy for itsget
orset
method.The current code is
The code could handle accessor functions with a third argument (either
"get"
or"set"
) like so:However, I'm not sure how this would break existing assumptions. For example, in my sample code above,
createSpy
is given the property name, but the property is not being spied on; rather, one of the property's accessor functions is being spied on. This change would require eliminating the assumption that a function being spied on is a property of an object, and instead writing logic that admits the possibility that a spied function could be aget
orset
function within an object property.The text was updated successfully, but these errors were encountered: