-
-
Notifications
You must be signed in to change notification settings - Fork 769
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 doesn't return the correct value when used with new #1676
Comments
In case you want to scratch your own itch, here is the piece of code where I would start looking into it: Lines 197 to 204 in a8171c3
|
I can reproduce this. I was using a |
Is there a way around this since "new" keyword is like default with ES6 can it support stubs themselves with objects.. |
I am sorry, but I do not understand what this means. Can you elaborate on what you mean? I especially do not understand what you mean by saying " |
Sorry i wrote in jiffy, I was trying to do following const instanceStub = sinon.stub();
const type = sinon.stub();
type.returns(instanceStub);
const instance = new type();
console.log(instance); //prints proxy function, expecting instanceStub The above failed if instanceStub was a Stub but if instanceStub is normal object then it passed. |
I am guessing |
Corrected code, ohh i saw the date now 🙂 |
The only issue I really see here is that we should perhaps be stricter about what we accept as a return value when newing objects. The only meaningful thing to return when invoking with TBH, I think an improvement would be to throw with a meaningful error message when encountering return values that are not objects, as that does not make sense. |
What did you expect to happen?
Stub to return the correct value when used with
new
.What actually happens
Returns a function
How to reproduce
The text was updated successfully, but these errors were encountered: