Skip to content

Commit

Permalink
Merge pull request #705 from janthoe/master
Browse files Browse the repository at this point in the history
fix: Check error object before updating stack. (Fixes #700)
  • Loading branch information
niftylettuce authored Jan 25, 2021
2 parents c21ba9a + b628d34 commit 8b0bf4d
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 8b0bf4d

Please sign in to comment.