|
|
@ -12,6 +12,15 @@ s.on('/invalid', function (req, res) { |
|
|
|
res.end('/'); |
|
|
|
}); |
|
|
|
|
|
|
|
s.on('/non200', function (req, res) { |
|
|
|
res.statusCode = 500; |
|
|
|
res.end('{"data":"dog"}'); |
|
|
|
}); |
|
|
|
|
|
|
|
s.on('/non200-invalid', function (req, res) { |
|
|
|
res.statusCode = 500; |
|
|
|
res.end('Internal error'); |
|
|
|
}); |
|
|
|
|
|
|
|
tape('setup', function (t) { |
|
|
|
s.listen(s.port, function () { |
|
|
@ -42,6 +51,22 @@ tape('json option wrap parsing errors', function (t) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
tape('json option should parse non-200 responses', function (t) { |
|
|
|
got(s.url + '/non200', {json: true}, function (err, json) { |
|
|
|
t.ok(err); |
|
|
|
t.deepEqual(json, {data: 'dog'}); |
|
|
|
t.end(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
tape('json option should catch errors on invalid non-200 responses', function (t) { |
|
|
|
got(s.url + '/non200-invalid', {json: true}, function (err, json) { |
|
|
|
t.ok(err); |
|
|
|
t.deepEqual(json, 'Internal error'); |
|
|
|
t.end(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
tape('cleanup', function (t) { |
|
|
|
s.close(); |
|
|
|
t.end(); |
|
|
|