Browse Source

throw exception, if url is not string or object

http2
Vsevolod Strukchinsky 10 years ago
parent
commit
6b015692aa
  1. 4
      index.js
  2. 15
      test/test-arguments.js

4
index.js

@ -25,6 +25,10 @@ util.inherits(GotError, NestedErrorStacks);
GotError.prototype.name = 'GotError';
function got(url, opts, cb) {
if (typeof url !== 'string' && !(url instanceof Object)) {
throw new GotError('Parameter \'url\' must be a string or object, not ' + typeof url);
}
if (typeof opts === 'function') {
cb = opts;
opts = {};

15
test/test-arguments.js

@ -18,6 +18,13 @@ tape('setup', function (t) {
});
});
tape('url argument is required', function (t) {
t.throws(function () {
got();
}, /Parameter 'url' must be a string or object, not undefined/);
t.end();
});
tape('accepts url.parse object as first argument', function (t) {
got({host: s.host, port: s.port, path: '/test'}, function (err, data) {
t.error(err);
@ -34,6 +41,14 @@ tape('extends parsed string with opts', function (t) {
});
});
tape('extends parsed string with opts', function (t) {
got(s.url + '/?test=doge', {query: {test: 'wow'}}, function (err, data) {
t.error(err);
t.equal(data, '/?test=wow');
t.end();
});
});
tape('cleanup', function (t) {
s.close();
t.end();

Loading…
Cancel
Save