Skip to content

Commit

Permalink
Update matchingFakes, always returns array
Browse files Browse the repository at this point in the history
  • Loading branch information
takasmiley committed Jun 28, 2017
1 parent f012fff commit e72fee4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
9 changes: 2 additions & 7 deletions lib/sinon/spy.js
Expand Up @@ -296,8 +296,7 @@ var spyApi = {
var args = slice.call(arguments);

if (this.fakes) {
var matchings = this.matchingFakes(args, true);
var matching = matchings && matchings.pop();
var matching = this.matchingFakes(args, true).pop();

if (matching) {
return matching;
Expand Down Expand Up @@ -335,11 +334,7 @@ var spyApi = {
},

matchingFakes: function (args, strict) {
if (!this.fakes) {
return undefined;
}

return this.fakes.filter(function (fake) {
return (this.fakes || []).filter(function (fake) {
return fake.matches(args, strict);
});
},
Expand Down
12 changes: 3 additions & 9 deletions lib/sinon/stub.js
Expand Up @@ -90,15 +90,9 @@ var proto = {
var args = slice.call(arguments);
var matchings = functionStub.matchingFakes(args);

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

Expand Down

0 comments on commit e72fee4

Please sign in to comment.