cjohansen/Sinon.JS — Issue #62: spy.args can give inaccurate results by referencing arguments
Author: ggoforth
Created: 2011-11-23 22:58:03+00:00
State: open

To see the issue: http://jsfiddle.net/93EVL/1/

Issue:
I ran into an issue today where sinon.args was not returning results I was expected. Seems like we would always want to know exactly what a function is called with.

Backstory:
We have some code where a function receives an options object, and one of the key is {retries: 3}. Our code will decrement retries, then call another function (that we are spying on) passing to it the options object, until retries === 0.
When all is said and done I would have expected to see:

ourSpiedOnFunction.args === [{retries: 2}, {retries: 1}, {retries: 0}]

but instead got:

ourSpiedOnFunction.args === [[retries: 0}, {retries: 0}, {retries: 0}]

So, it seems like sinon holds onto the arguments by reference, which is causing this issue. Demonstration of the issue here: http://jsfiddle.net/93EVL/1/