Skip to content

Commit

Permalink
Merge pull request #1359 from kevincennis/kce/fix-1066
Browse files Browse the repository at this point in the history
Fix error on call.toString() where stack has fewer than 4 lines.
  • Loading branch information
fatso83 authored Mar 27, 2017
2 parents c633202 + f93cd3b commit c5bc9ab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sinon/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions test/call-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit c5bc9ab

Please sign in to comment.