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
Stub of getters & setters not working with sandbox #781
Comments
Thank you for reporting this.
That's a good question. We'll need more investigation to determine if that's possible. |
I recently added sinon to a project, to augment Jasmine, specifically because it supported mocking properties. I would use this feature as soon as it was available. |
I just hit this issue as well. |
The same issue |
Just ran into this issue |
As the label says: help is much appreciated. If someone deeply craves this feature do know that we are open for pull requests ;-) |
@fatso83 I'll give adding some unit tests and fixing this a go... fingers crossed I can get it working 😄 |
@mmoss Make sure to pull again. The unit tests have been converted to Mocha. |
Hi everyone, I have been investigating this and I've found inconsistencies with the request and how it currently works. According to the docs, the
Due to this fact it's not viable to make it accept property descriptors as values, because then we wouldn't be able to know whether the user wants to pass a property descriptor or an simple object to replace that property. For example: var myModule = {
doubles: {
get: function get(x) {
return x * 2;
}
}
};
var sandbox = sinon.sandbox.create();
// If we were able to do this, how can we know if the third argument is a property descriptor or if it should simply replace the property `get`?
sandbox.stub(myModule, 'doubles', {
get: function get() {
return -1
}
});
// Now should this return -1 or should this return an object with a `get` function?
console.log(myModule.doubles); I think that by adding this feature we would end up causing confusion, even though we check for the names in the object passed, someone may have names which end up clashing with property that do exist on property descriptors. We can't just arbitrarily infer what the user wants. I can think of three ways to solve this problem:
Let me know what you'd like and I'll make a PR for that. Also, if I misunderstood something or said anything wrong please let me know. Thanks! |
This is implemented with #1416 |
When I stub getter using
sinon.stub()
everything works fine.But when I use
sandbox.stub()
it does not work.Example:
jsfiddle: http://jsfiddle.net/exzc5m3e/
Relates to: #692
Is it possible to support getters & setters in sandboxes?
Thanks!
The text was updated successfully, but these errors were encountered: