Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concat: add test coverage for error res/data #66

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 24 additions & 1 deletion test/concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()
})
})
Expand Down