Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error on call.toString() where stack has fewer than 4 lines. #1359

Merged
merged 1 commit into from
Mar 27, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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