Skip to content

Commit

Permalink
Add test for adding stack traces to error message
Browse files Browse the repository at this point in the history
This ensures that if at some point we end up with another Sinon layer in
the stack at some point, we'll catch it and hopefully adjust accordingly

For reference, as of this commit, the Sinon portion of the stack is:
lib/sinon/proxy-invoke.js:65:15
lib/sinon/proxy.js:265:26

Also convert a neighboring test to async while we're at it
  • Loading branch information
cincodenada committed Jan 20, 2022
1 parent 078f3a8 commit 196f432
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions test/proxy-call-test.js
Expand Up @@ -1176,29 +1176,41 @@ describe("sinonSpy.call", function () {

// https://github.com/sinonjs/sinon/issues/1066
/* eslint-disable consistent-return */
it("does not throw when the call stack is empty", function (done) {
it("does not throw when the call stack is empty", async function () {
if (typeof Promise === "undefined") {
this.skip();
}

var stub1 = sinonStub().resolves(1);
var stub2 = sinonStub().returns(1);

function run() {
return stub1().then(stub2);
}
await stub2(await stub1())

run()
.then(function () {
assert.equals(
stub2.getCall(0).toString().replace(/ at.*/g, ""),
"stub(1) => 1"
);
done();
})
.catch(done);
assert.equals(
stub2.getCall(0).toString().replace(/ at.*/g, ""),
"stub(1) => 1"
);
});
/* eslint-enable consistent-return */

it("includes first stack entry from end-user code", function () {
/* We find the first stack frame that points to end-user code and
* add it to the error message. We do this by chopping off a
* constant number of stack frames, so if this test fails, you
* probably need to chop off a different number of frames
*/
if (typeof __filename === "undefined") {
this.skip()
}

var object = { doIt: sinonSpy() };
object.doIt();

const [name, stackFrame] = object.doIt.getCall(0).toString().split(" at ")

assert.equals(name, "doIt()");
assert.contains(stackFrame, __filename);
});
});

describe("constructor", function () {
Expand Down

0 comments on commit 196f432

Please sign in to comment.