Running the function stubbed in the below example should return 1 as this satisfies the first withArgs setup. However, with the introduction of the second withArgs setup the return value becomes 2.
function Example() {
this.doSomething = function () { };
}
var example = new Example();
sinon.stub(example, 'doSomething');
example.doSomething.withArgs(sinon.match(function() { return true; })).returns(1);
example.doSomething.withArgs(sinon.match(function() { return false; })).returns(2);
equal(example.doSomething({}), 2); //should fail. passes
Hi, this does seem wrong. Mind seeing if this bug is present in Sinon 2 (npm i sinon@next)?
Just tried it in Sinon 2 and the bug is still present.
Hi friends, I have just tested this against master and it seems to be working.
Here is the code I've written to test it:
describe("#1197", function () {
it.only("Returns correct value according to matcher with multiple .withArgs", function () {
function Example() {
this.doSomething = function () { };
}
var example = new Example();
sinon.stub(example, 'doSomething');
example.doSomething.withArgs(sinon.match(function() { return true; })).returns(1);
example.doSomething.withArgs(sinon.match(function() { return false; })).returns(2);
// This passes, as it should
assert.equals(example.doSomething({}), 1);
});
});
As you can see, the stubbed function returns 1 as expected due to its matcher always returning true.
Let me know if I did anything wrong or if I misunderstood anything.
Hi, I've just retested it myself on a build from master and it is indeed fixed now. The version I installed earlier is dated 31/12/2016 so this bug was obviously fixed very recently! Thanks.
This seems to be fixed, I am closing it
Most helpful comment
Hi, I've just retested it myself on a build from
masterand it is indeed fixed now. The version I installed earlier is dated 31/12/2016 so this bug was obviously fixed very recently! Thanks.