Skip to content

Commit

Permalink
Merge 1ce9e10 into 15a9d65
Browse files Browse the repository at this point in the history
  • Loading branch information
mgabeler-lee-6rs committed May 2, 2019
2 parents 15a9d65 + 1ce9e10 commit 843ba55
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
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 @@ -599,4 +599,24 @@ describe("issues", function() {
assert.equals(fake.lastArg, false);
});
});

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);
});
});
});

0 comments on commit 843ba55

Please sign in to comment.