Comparing version 2.3.5 to 2.3.6
2.3.6 / 2017-06-28 | ||
================== | ||
* Fix #1274: spy.withArgs(args...).callCount is incorrect | ||
2.3.5 / 2017-06-20 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -5,4 +5,6 @@ # Contributing to Sinon.JS | ||
* Help [improve the documentation](https://github.com/sinonjs/sinon-docs) published at [the Sinon.JS website](http://sinonjs.org) | ||
* Help someone understand and use Sinon.JS on [the mailing list](http://groups.google.com/group/sinonjs) | ||
* Look into [issues tagged `help-wanted`](https://github.com/sinonjs/sinon/issues?q=is%3Aopen+is%3Aissue+label%3A%22Help+wanted%22) | ||
* Help [improve the documentation](https://github.com/sinonjs/sinon/tree/master/docs) published | ||
at [the Sinon.JS website](http://sinonjs.org). [Documentation issues](https://github.com/sinonjs/sinon/issues?q=is%3Aopen+is%3Aissue+label%3ADocumentation). | ||
* Help someone understand and use Sinon.JS on [the mailing list](http://groups.google.com/group/sinonjs) or on [Stack Overflow](https://stackoverflow.com/questions/tagged/sinon) | ||
* Report an issue, please read instructions below | ||
@@ -9,0 +11,0 @@ * Help with triaging the [issues](http://github.com/cjohansen/Sinon.JS/issues). The clearer they are, the more likely they are to be fixed soon. |
@@ -44,14 +44,2 @@ "use strict"; | ||
function matchingFake(fakes, args, strict) { | ||
if (!fakes) { | ||
return undefined; | ||
} | ||
var matchingFakes = fakes.filter(function (fake) { | ||
return fake.matches(args, strict); | ||
}); | ||
return matchingFakes.pop(); | ||
} | ||
function incrementCallCount() { | ||
@@ -178,3 +166,4 @@ this.called = true; | ||
invoke: function invoke(func, thisValue, args) { | ||
var matching = matchingFake(this.fakes, args); | ||
var matchings = this.matchingFakes(args); | ||
var currentCallId = callId++; | ||
var exception, returnValue; | ||
@@ -185,3 +174,9 @@ | ||
push.call(this.args, args); | ||
push.call(this.callIds, callId++); | ||
push.call(this.callIds, currentCallId); | ||
matchings.forEach(function (matching) { | ||
incrementCallCount.call(matching); | ||
push.call(matching.thisValues, thisValue); | ||
push.call(matching.args, args); | ||
push.call(matching.callIds, currentCallId); | ||
}); | ||
@@ -194,7 +189,3 @@ // Make call properties available from within the spied function: | ||
if (matching) { | ||
returnValue = matching.invoke(func, thisValue, args); | ||
} else { | ||
returnValue = (this.func || func).apply(thisValue, args); | ||
} | ||
returnValue = (this.func || func).apply(thisValue, args); | ||
@@ -213,2 +204,7 @@ var thisCall = this.getCall(this.callCount - 1); | ||
push.call(this.returnValues, returnValue); | ||
matchings.forEach(function (matching) { | ||
push.call(matching.exceptions, exception); | ||
push.call(matching.returnValues, returnValue); | ||
}); | ||
var err = new ErrorConstructor(); | ||
@@ -222,2 +218,5 @@ // 1. Please do not get stack at this point. It may be so very slow, and not actually used | ||
push.call(this.errorsWithCallStack, err); | ||
matchings.forEach(function (matching) { | ||
push.call(matching.errorsWithCallStack, err); | ||
}); | ||
@@ -300,6 +299,6 @@ // Make return value and exception available in the calls: | ||
if (this.fakes) { | ||
var match = matchingFake(this.fakes, args, true); | ||
var matching = this.matchingFakes(args, true).pop(); | ||
if (match) { | ||
return match; | ||
if (matching) { | ||
return matching; | ||
} | ||
@@ -338,2 +337,8 @@ } else { | ||
matchingFakes: function (args, strict) { | ||
return (this.fakes || []).filter(function (fake) { | ||
return fake.matches(args, strict); | ||
}); | ||
}, | ||
matches: function (args, strict) { | ||
@@ -340,0 +345,0 @@ var margs = this.matchingArguments; |
@@ -14,2 +14,4 @@ "use strict"; | ||
var slice = Array.prototype.slice; | ||
function stub(object, property, descriptor) { | ||
@@ -89,3 +91,9 @@ throwOnFalsyObject.apply(null, arguments); | ||
var functionStub = function () { | ||
return getCurrentBehavior(functionStub).invoke(this, arguments); | ||
var args = slice.call(arguments); | ||
var matchings = functionStub.matchingFakes(args); | ||
var fnStub = matchings.sort(function (a, b) { | ||
return a.matchingArguments.length - b.matchingArguments.length; | ||
}).pop() || functionStub; | ||
return getCurrentBehavior(fnStub).invoke(this, arguments); | ||
}; | ||
@@ -92,0 +100,0 @@ |
{ | ||
"name": "sinon", | ||
"description": "JavaScript test spies, stubs and mocks.", | ||
"version": "2.3.5", | ||
"version": "2.3.6", | ||
"homepage": "http://sinonjs.org/", | ||
@@ -6,0 +6,0 @@ "author": "Christian Johansen", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
6382974
61708