File tree 3 files changed +19
-7
lines changed
3 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -303,7 +303,12 @@ function wrapAssertFn(assertFn) {
303
303
304
304
return function ( res ) {
305
305
let badStack ;
306
- const err = assertFn ( res ) ;
306
+ let err ;
307
+ try {
308
+ err = assertFn ( res ) ;
309
+ } catch ( e ) {
310
+ err = e ;
311
+ }
307
312
if ( err instanceof Error && err . stack ) {
308
313
badStack = err . stack . replace ( err . message , '' ) . split ( '\n' ) . slice ( 1 ) ;
309
314
err . stack = [ err . toString ( ) ]
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ const bodyParser = require('body-parser');
9
9
const cookieParser = require ( 'cookie-parser' ) ;
10
10
const nock = require ( 'nock' ) ;
11
11
const request = require ( '../index.js' ) ;
12
+ const throwError = require ( './throwError' ) ;
12
13
13
14
process . env . NODE_TLS_REJECT_UNAUTHORIZED = '0' ;
14
15
@@ -750,9 +751,7 @@ describe('request(app)', function () {
750
751
751
752
it ( 'reports errors' , function ( done ) {
752
753
get
753
- . expect ( function ( res ) {
754
- throw new Error ( 'failed' ) ;
755
- } )
754
+ . expect ( throwError ( 'failed' ) )
756
755
. end ( function ( err ) {
757
756
err . message . should . equal ( 'failed' ) ;
758
757
shouldIncludeStackWithThisFile ( err ) ;
@@ -776,9 +775,7 @@ describe('request(app)', function () {
776
775
777
776
it ( 'ensures truthy errors returned from asserts are throw to end' , function ( done ) {
778
777
get
779
- . expect ( function ( res ) {
780
- return new Error ( 'some descriptive error' ) ;
781
- } )
778
+ . expect ( throwError ( 'some descriptive error' ) )
782
779
. end ( function ( err ) {
783
780
err . message . should . equal ( 'some descriptive error' ) ;
784
781
shouldIncludeStackWithThisFile ( err ) ;
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments