You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi I'm currently using SinonJS (v. 1.17.3 on Node.js 4.x) and I'm experiencing a small problem while restoring a mocked getter. There's this little code in the restore method:
This can sometimes cause problems if object[property] is a getter. I suggest the check is only performed if Object.defineProperty wasn't called before, as at this point we are sure that the property has been restored and the check is unnecessary.
Because the authors of SinonJS aren't very fond of mocking getters/setters, let me provide you with a bit of a background.
Here's a class that contains the getter I'm mocking:
I'm using this class inside some function that I'm testing and I wanted to check if the errors are passed correctly. Because I can't manipulate the object itself, I turned to the prototype, and so I've written:
Later on I want to clean up, and so I call stub.restore(). This obviously causes an error, because at the point object[property] is called the getter has been restored, and so the call really looks like this: privateDataMap.get(DataStore.prototype).errors;.
Because I can't access privateDataMap from the outside (that's the point), I can't set the value for privateDataMap.get(DataStore.prototype), and so a type error occurs.
The text was updated successfully, but these errors were encountered:
Last year - feel free to push it forwards :-) No seriously, it's getting there a lot faster nowadays with the help we have been getting on #966 from (amongst others) @fearphage and @jonnyreeves , but there is still quite a bit left.
You can get the next pre-release by doing npm install sinon@next
Hi I'm currently using SinonJS (v. 1.17.3 on Node.js 4.x) and I'm experiencing a small problem while restoring a mocked getter. There's this little code in the
restore
method:This can sometimes cause problems if
object[property]
is a getter. I suggest the check is only performed ifObject.defineProperty
wasn't called before, as at this point we are sure that the property has been restored and the check is unnecessary.Because the authors of SinonJS aren't very fond of mocking getters/setters, let me provide you with a bit of a background.
Here's a class that contains the getter I'm mocking:
I'm using this class inside some function that I'm testing and I wanted to check if the errors are passed correctly. Because I can't manipulate the object itself, I turned to the prototype, and so I've written:
Later on I want to clean up, and so I call
stub.restore()
. This obviously causes an error, because at the pointobject[property]
is called the getter has been restored, and so the call really looks like this:privateDataMap.get(DataStore.prototype).errors;
.Because I can't access
privateDataMap
from the outside (that's the point), I can't set the value forprivateDataMap.get(DataStore.prototype)
, and so a type error occurs.The text was updated successfully, but these errors were encountered: