Browse Source

small fixes in validation

http2
Vsevolod Strukchinsky 10 years ago
parent
commit
0797e46608
  1. 6
      index.js
  2. 12
      test/test-arguments.js

6
index.js

@ -25,8 +25,8 @@ 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 url !== 'string' && typeof url !== 'object') {
throw new GotError('Parameter `url` must be a string or object, not ' + typeof url);
}
if (typeof opts === 'function') {
@ -74,7 +74,7 @@ function got(url, opts, cb) {
throw new GotError('got can not be used as stream when options.json is used');
}
if (body && !(typeof body === 'string' || body instanceof Buffer || isStream.readable(body))) {
if (body && !(typeof body === 'string' || Buffer.isBuffer(body) || isStream.readable(body))) {
throw new GotError('options.body must be a ReadableStream, string or Buffer');
}

12
test/test-arguments.js

@ -21,7 +21,7 @@ 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/);
}, /Parameter `url` must be a string or object, not undefined/);
t.end();
});
@ -33,15 +33,7 @@ tape('accepts url.parse object as first argument', function (t) {
});
});
tape('extends parsed string with opts', function (t) {
got(s.url, {path: '/test'}, function (err, data) {
t.error(err);
t.equal(data, '/test');
t.end();
});
});
tape('extends parsed string with opts', function (t) {
tape('overrides querystring from opts', function (t) {
got(s.url + '/?test=doge', {query: {test: 'wow'}}, function (err, data) {
t.error(err);
t.equal(data, '/?test=wow');

Loading…
Cancel
Save