From b24da855443221dd13c391aae9c4c40c7bd8fe7d Mon Sep 17 00:00:00 2001 From: Alexandre ABRIOUX Date: Tue, 29 Mar 2022 14:35:03 +0200 Subject: [PATCH] test: add failing test --- test/supertest.js | 9 +++------ test/throwError.js | 10 ++++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 test/throwError.js diff --git a/test/supertest.js b/test/supertest.js index 7561d1f..cbb36a6 100644 --- a/test/supertest.js +++ b/test/supertest.js @@ -9,6 +9,7 @@ const bodyParser = require('body-parser'); const cookieParser = require('cookie-parser'); const nock = require('nock'); const request = require('../index.js'); +const throwError = require('./throwError'); process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; @@ -748,9 +749,7 @@ describe('request(app)', function () { it('reports errors', function (done) { get - .expect(function (res) { - throw new Error('failed'); - }) + .expect(throwError('failed')) .end(function (err) { err.message.should.equal('failed'); shouldIncludeStackWithThisFile(err); @@ -774,9 +773,7 @@ describe('request(app)', function () { it('ensures truthy errors returned from asserts are throw to end', function (done) { get - .expect(function (res) { - return new Error('some descriptive error'); - }) + .expect(throwError('some descriptive error')) .end(function (err) { err.message.should.equal('some descriptive error'); shouldIncludeStackWithThisFile(err); diff --git a/test/throwError.js b/test/throwError.js new file mode 100644 index 0000000..ce7ee52 --- /dev/null +++ b/test/throwError.js @@ -0,0 +1,10 @@ +'use strict'; + +/** + * This method needs to reside in its own module in order to properly test stack trace handling. + */ +module.exports = function throwError(message) { + return function() { + throw new Error(message); + }; +};