@@ -1269,7 +1269,7 @@ describe('request.get(url).query(vals) works as expected', function () {
1269
1269
} ) ;
1270
1270
} ) ;
1271
1271
1272
- it ( 'handles unknown errors' , function ( done ) {
1272
+ it ( 'handles unknown errors (err without res) ' , function ( done ) {
1273
1273
const app = express ( ) ;
1274
1274
1275
1275
nock . disableNetConnect ( ) ;
@@ -1285,6 +1285,8 @@ describe('request.get(url).query(vals) works as expected', function () {
1285
1285
// https://github.com/visionmedia/supertest/issues/352
1286
1286
. expect ( 200 )
1287
1287
. end ( function ( err , res ) {
1288
+ should . exist ( err ) ;
1289
+ should . not . exist ( res ) ;
1288
1290
err . should . be . an . instanceof ( Error ) ;
1289
1291
err . message . should . match ( / N o c k : D i s a l l o w e d n e t c o n n e c t / ) ;
1290
1292
shouldIncludeStackWithThisFile ( err ) ;
@@ -1294,6 +1296,35 @@ describe('request.get(url).query(vals) works as expected', function () {
1294
1296
nock . restore ( ) ;
1295
1297
} ) ;
1296
1298
1299
+ // this scenario should never happen
1300
+ // there shouldn't be any res if there is an err
1301
+ // meant for test coverage for lib/test.js#169
1302
+ // https://github.com/visionmedia/supertest/blob/5543d674cf9aa4547927ba6010d31d9474950dec/lib/test.js#L169
1303
+ it ( 'handles unknown errors (err with res)' , function ( done ) {
1304
+ const app = express ( ) ;
1305
+
1306
+ app . get ( '/' , function ( req , res ) {
1307
+ res . status ( 200 ) . send ( 'OK' ) ;
1308
+ } ) ;
1309
+
1310
+ const resError = new Error ( ) ;
1311
+ resError . status = 400 ;
1312
+
1313
+ const serverRes = { status : 200 } ;
1314
+
1315
+ request ( app )
1316
+ . get ( '/' )
1317
+ // private api
1318
+ . assert ( resError , serverRes , function ( err , res ) {
1319
+ should . exist ( err ) ;
1320
+ should . exist ( res ) ;
1321
+ err . should . equal ( resError ) ;
1322
+ res . should . equal ( serverRes ) ;
1323
+ // close the server explicitly (as we are not using expect/end/then)
1324
+ this . end ( done ) ;
1325
+ } ) ;
1326
+ } ) ;
1327
+
1297
1328
it ( 'should assert using promises' , function ( done ) {
1298
1329
const app = express ( ) ;
1299
1330
0 commit comments