Skip to content

Commit e72fee4

Browse files
author
takasmiley
committed
Update matchingFakes, always returns array
1 parent f012fff commit e72fee4

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

lib/sinon/spy.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,7 @@ var spyApi = {
296296
var args = slice.call(arguments);
297297

298298
if (this.fakes) {
299-
var matchings = this.matchingFakes(args, true);
300-
var matching = matchings && matchings.pop();
299+
var matching = this.matchingFakes(args, true).pop();
301300

302301
if (matching) {
303302
return matching;
@@ -335,11 +334,7 @@ var spyApi = {
335334
},
336335

337336
matchingFakes: function (args, strict) {
338-
if (!this.fakes) {
339-
return undefined;
340-
}
341-
342-
return this.fakes.filter(function (fake) {
337+
return (this.fakes || []).filter(function (fake) {
343338
return fake.matches(args, strict);
344339
});
345340
},

lib/sinon/stub.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,9 @@ var proto = {
9090
var args = slice.call(arguments);
9191
var matchings = functionStub.matchingFakes(args);
9292

93-
var fnStub;
94-
if (matchings) {
95-
fnStub = matchings.sort(function (a, b) {
96-
return a.matchingArguments.length - b.matchingArguments.length;
97-
}).pop();
98-
}
99-
if (!fnStub) {
100-
fnStub = functionStub;
101-
}
93+
var fnStub = matchings.sort(function (a, b) {
94+
return a.matchingArguments.length - b.matchingArguments.length;
95+
}).pop() || functionStub;
10296
return getCurrentBehavior(fnStub).invoke(this, arguments);
10397
};
10498

0 commit comments

Comments
 (0)