-
-
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
returnValue of calls is out of order when spying on recursive functions #1849
Comments
Hmm ... any idea of how to fix this? |
I edited the description to add language annotations to the the fenced blocks to allow GFM to do syntax highlighting |
This doesn't work the way you think. The problem is the inner function has a closure so it never calls the (outer) fake in my testing. Is http://jsbin.com/sevesibibu/edit?js,console I don't think this is a problem that sinon can resolve honestly. |
@fearphage Your example is not actually replacing the function Compare to this: let count = 0;
function foo(num) {
console.log(`foo called: ${++count}; num: ${num}`);
if (num < 5) {
return num + foo(num + 1);
}
return num;
}
foo = sinon.fake(foo);
const result = foo(2);
console.log(`fake call count: ${foo.callCount}, result: ${result}`); |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Describe the bug
The return value, as given by
spy.getCall(n).returnValue
, is in the wrong order when spying on a recursive function. The return values are in the order that calls returned, instead of the order of the calls themselves. For example, the returnValue of the first call is the value returned by the last call, instead of the value returned by the first call.Note that this bug occurs with both
sinon.spy
andsinon.fake
.To Reproduce
recurse.js
recurse.test.js
Expected behavior
spy.getCall(n).returnValue
should be the return value of the nth call to spy.Context:
The text was updated successfully, but these errors were encountered: