From febe29295f1db149a18ee4dfc9a152f9d7198b7b Mon Sep 17 00:00:00 2001 From: Ben Drucker Date: Wed, 12 May 2021 10:01:27 -0700 Subject: [PATCH] concat: add test coverage for res/data --- test/concat.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/test/concat.js b/test/concat.js index 2bc22c9..40684fb 100644 --- a/test/concat.js +++ b/test/concat.js @@ -70,8 +70,29 @@ test('get.concat json', function (t) { }) }) +test('get.concat response error status', function (t) { + t.plan(3) + const server = http.createServer(function (req, res) { + res.statusCode = 500 + res.end('fail') + }) + + server.listen(0, function () { + const port = server.address().port + const opts = { + url: 'http://localhost:' + port + '/path' + } + get.concat(opts, function (err, res, data) { + t.equal(err, null) + t.equal(res.statusCode, 500) + t.equal(data.toString(), 'fail') + server.close() + }) + }) +}) + test('get.concat json error', function (t) { - t.plan(1) + t.plan(3) const server = http.createServer(function (req, res) { res.statusCode = 500 res.end('not json') @@ -85,6 +106,8 @@ test('get.concat json error', function (t) { } get.concat(opts, function (err, res, data) { t.ok(err instanceof Error) + t.equal(res.statusCode, 500) + t.equal(data.toString(), 'not json') server.close() }) })