-
-
Notifications
You must be signed in to change notification settings - Fork 771
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
cannot stub newly created net.Socket #216
Comments
Okay, more info. The offending property is 'remoteAddress', which is a "getter", defined as:
My read is that because it's defined as a Getter, it automatically executes the behavior, which we don't want in this case. Instead it needs to be special cased, and that behavior dropped. I don't know how to detect getters. Still looking. |
Sinon doesn't properly support getters and setters. I guess ideally the code should feature detect |
I just tried that, and it doesn't work. net.Socket.remoteAddress is defined this way:
and my code tried this:
propDesc was undefined. Other ideas? |
Is it an inherited property then? My suggestion is to not rely on the var socket = { remoteAddress: "0.0.0.0", on: sinon.spy(), ... }; |
That's what I've already begun. But life is better if I can simply sinon.stub(obj) and roll on :) |
Ok. I have a diff principle. I suspect it needs to also handle the getPropertyDescriptor case as well, and don't know where setters fit into this. (I've been coding in Node on and off for a couple months, and lack depth in understanding, frankly.) In any case, this works for net.Socket. This is patched against HEAD, not 1.3.4. But I'm running it against 1.3.4, as mentioned. Thoughts?
|
Any news on Sinon spies and stubs supporting getters and setters? |
I would like to have it, also for the 'value' of an ES5 defineProperty ! ... So, any news or ideas on how to use Sinon stubs with these properties ? |
I've made graceful failure for getters a release goal for Sinon 2.0: #600 |
Attempts at stub()ing a Socket have failed. I debugged a little bit, and it appears to walk quite a way through the property list before failing. I will spend a bit more effort on it, but thought it worth filing at this point.
Sample code:
Failure:
The text was updated successfully, but these errors were encountered: