diff --git a/lib/sinon/call.js b/lib/sinon/call.js index 38bf8076c..9d8a2aab4 100644 --- a/lib/sinon/call.js +++ b/lib/sinon/call.js @@ -176,7 +176,7 @@ var callProto = { } if (this.stack) { // Omit the error message and the two top stack frames in sinon itself: - callStr += this.stack.split("\n")[3].replace(/^\s*(?:at\s+|@)?/, " at "); + callStr += ( this.stack.split("\n")[3] || "unknown" ).replace(/^\s*(?:at\s+|@)?/, " at "); } return callStr; diff --git a/test/call-test.js b/test/call-test.js index 3a080a20d..31b919a4f 100644 --- a/test/call-test.js +++ b/test/call-test.js @@ -835,6 +835,23 @@ describe("sinonSpy.call", function () { assert.equals(object.doIt.getCall(0).toString().replace(/ at.*/g, ""), "doIt() => 42"); }); + + // https://github.com/sinonjs/sinon/issues/1066 + it("does not throw when the call stack is empty", function (done) { + var stub1 = sinonStub().resolves(1); + var stub2 = sinonStub().returns(1); + + function run() { + return stub1().then(stub2); + } + + run() + .then(function () { + assert.equals(stub2.getCall(0).toString().replace(/ at.*/g, ""), "stub(1) => 1"); + done(); + }) + .catch( done ); + }); }); describe("constructor", function () {