diff --git a/test/supertest.js b/test/supertest.js index 7561d1f..d108b63 100644 --- a/test/supertest.js +++ b/test/supertest.js @@ -1269,7 +1269,7 @@ describe('request.get(url).query(vals) works as expected', function () { }); }); - it('handles unknown errors', function (done) { + it('handles unknown errors (err without res)', function (done) { const app = express(); nock.disableNetConnect(); @@ -1285,6 +1285,8 @@ describe('request.get(url).query(vals) works as expected', function () { // https://github.com/visionmedia/supertest/issues/352 .expect(200) .end(function (err, res) { + should.exist(err); + should.not.exist(res); err.should.be.an.instanceof(Error); err.message.should.match(/Nock: Disallowed net connect/); shouldIncludeStackWithThisFile(err); @@ -1294,6 +1296,35 @@ describe('request.get(url).query(vals) works as expected', function () { nock.restore(); }); + // this scenario should never happen + // there shouldn't be any res if there is an err + // meant for test coverage for lib/test.js#169 + // https://github.com/visionmedia/supertest/blob/5543d674cf9aa4547927ba6010d31d9474950dec/lib/test.js#L169 + it('handles unknown errors (err with res)', function (done) { + const app = express(); + + app.get('/', function (req, res) { + res.status(200).send('OK'); + }); + + const resError = new Error(); + resError.status = 400; + + const serverRes = { status: 200 }; + + request(app) + .get('/') + // private api + .assert(resError, serverRes, function (err, res) { + should.exist(err); + should.exist(res); + err.should.equal(resError); + res.should.equal(serverRes); + // close the server explicitly (as we are not using expect/end/then) + this.end(done); + }); + }); + it('should assert using promises', function (done) { const app = express();