Skip to content

Commit

Permalink
test: add failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-abrioux committed Mar 29, 2022
1 parent e6d371c commit b24da85
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 3 additions & 6 deletions test/supertest.js
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions 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);
};
};

0 comments on commit b24da85

Please sign in to comment.