Skip to content

Commit

Permalink
fix: Check error object before updating stack. (Fixes #700)
Browse files Browse the repository at this point in the history
  • Loading branch information
janthoe committed Jan 25, 2021
1 parent c21ba9a commit b628d34
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function wrapAssertFn(assertFn) {
return function(res) {
var badStack;
var err = assertFn(res);
if (err && err.stack) {
if (err instanceof Error && err.stack) {
badStack = err.stack.replace(err.message, '').split('\n').slice(1);
err.stack = [err.toString()]
.concat(savedStack)
Expand Down
12 changes: 12 additions & 0 deletions test/supertest.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,18 @@ describe('request(app)', function () {
.end(done);
});

it("doesn't create false negatives on non error objects", function (done) {
const handler = {
get: function(target, prop, receiver) {
throw Error('Should not be called for non Error objects');
}
};
const proxy = new Proxy({}, handler); // eslint-disable-line no-undef
get
.expect(() => proxy)
.end(done);
});

it('handles multiple asserts', function (done) {
const calls = [];
get
Expand Down

0 comments on commit b628d34

Please sign in to comment.