Skip to content

Commit

Permalink
Fix stub.withArgs(args...) is incorrect
Browse files Browse the repository at this point in the history
Change last pop to the most matched arguments at stub.
  • Loading branch information
takasmiley committed Jun 28, 2017
1 parent 76ac773 commit f012fff
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/sinon/stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,15 @@ var proto = {
var args = slice.call(arguments);
var matchings = functionStub.matchingFakes(args);

var fnStub = (matchings && matchings.pop()) || functionStub;
var fnStub;
if (matchings) {
fnStub = matchings.sort(function (a, b) {
return a.matchingArguments.length - b.matchingArguments.length;
}).pop();
}
if (!fnStub) {
fnStub = functionStub;
}
return getCurrentBehavior(fnStub).invoke(this, arguments);
};

Expand Down

0 comments on commit f012fff

Please sign in to comment.