Browse Source

throw when callback is passed to stream mode

http2
Vsevolod Strukchinsky 9 years ago
parent
commit
df26918b3d
  1. 6
      index.js
  2. 12
      test/test-stream.js

6
index.js

@ -288,7 +288,11 @@ helpers.forEach(function (el) {
};
});
got.stream = function (url, opts) {
got.stream = function (url, opts, cb) {
if (cb || typeof opts === 'function') {
throw new Error('callback can not be used with stream mode');
}
return asStream(normalizeArguments(url, opts));
};

12
test/test-stream.js

@ -37,6 +37,18 @@ test('json option can not be used in stream mode', function (t) {
t.end();
});
test('callback can not be used in stream mode', function (t) {
t.throws(function () {
got.stream(s.url, {json: true}, function () {});
}, 'callback can not be used in stream mode');
t.throws(function () {
got.stream(s.url, function () {});
}, 'callback can not be used in stream mode');
t.end();
});
test('return readable stream', function (t) {
got.stream(s.url)
.on('data', function (data) {

Loading…
Cancel
Save