Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/sinon/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ var proto = {
} else if (this.reject) {
return (this.promiseLibrary || Promise).reject(this.returnValue);
} else if (this.callsThrough) {
return this.stub.wrappedMethod.apply(context, args);
var wrappedMethod = this.effectiveWrappedMethod();
return wrappedMethod.apply(context, args);
} else if (typeof this.returnValue !== "undefined") {
return this.returnValue;
} else if (typeof this.callArgAt === "number") {
Expand All @@ -180,6 +181,15 @@ var proto = {
return this.returnValue;
},

effectiveWrappedMethod: function effectiveWrappedMethod() {
for (var stubb = this.stub; stubb; stubb = stubb.parent) {
if (stubb.wrappedMethod) {
return stubb.wrappedMethod;
}
}
throw new Error("Unable to find wrapped method");
},

onCall: function onCall(index) {
return this.stub.onCall(index);
},
Expand Down
20 changes: 20 additions & 0 deletions test/issues/issues-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,26 @@ describe("issues", function() {
});
});

describe("#1964", function() {
it("should allow callThrough on a withArgs fake", function() {
var calledThrough = false;
var obj = {
method: function() {
calledThrough = true;
}
};

var baseStub = sinon.stub(obj, "method");
baseStub.throws("Should always hit the withArgs fake");
var argsStub = baseStub.withArgs("foo").callThrough();

obj.method("foo");

sinon.assert.calledOnce(argsStub);
assert.isTrue(calledThrough);
});
});

describe("#2016", function() {
function Foo() {
return;
Expand Down