Skip to content

Commit b24da85

Browse files
committedMar 29, 2022
test: add failing test
1 parent e6d371c commit b24da85

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed
 

‎test/supertest.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const bodyParser = require('body-parser');
99
const cookieParser = require('cookie-parser');
1010
const nock = require('nock');
1111
const request = require('../index.js');
12+
const throwError = require('./throwError');
1213

1314
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
1415

@@ -748,9 +749,7 @@ describe('request(app)', function () {
748749

749750
it('reports errors', function (done) {
750751
get
751-
.expect(function (res) {
752-
throw new Error('failed');
753-
})
752+
.expect(throwError('failed'))
754753
.end(function (err) {
755754
err.message.should.equal('failed');
756755
shouldIncludeStackWithThisFile(err);
@@ -774,9 +773,7 @@ describe('request(app)', function () {
774773

775774
it('ensures truthy errors returned from asserts are throw to end', function (done) {
776775
get
777-
.expect(function (res) {
778-
return new Error('some descriptive error');
779-
})
776+
.expect(throwError('some descriptive error'))
780777
.end(function (err) {
781778
err.message.should.equal('some descriptive error');
782779
shouldIncludeStackWithThisFile(err);

‎test/throwError.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
/**
4+
* This method needs to reside in its own module in order to properly test stack trace handling.
5+
*/
6+
module.exports = function throwError(message) {
7+
return function() {
8+
throw new Error(message);
9+
};
10+
};

0 commit comments

Comments
 (0)
Please sign in to comment.