Skip to content

Commit

Permalink
test: Stream request body
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Krems committed Apr 18, 2016
1 parent 8c84f46 commit 4ed4471
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions test/request-body.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,34 @@ describe('fetch: sending a body', function () {
});
});

it('can send a node ReadableStream', function () {
if (typeof document !== 'undefined') {
return this.skip();
}
var Readable = require('stream').Readable;

var stream = new Readable();
var characters = ['I', '💖', '🍕'];
stream._read = function _read() {
setTimeout(function doPush() {
stream.push(characters.shift() || null);
}, 5);
};

var withStreamBody = {
baseUrl: defaultOptions.baseUrl,
method: 'PUT',
body: stream,
};
return client.echo(withStreamBody)
.then(function (echo) {
assert.equal('PUT', echo.method);
// it should chunk the response
assert.equal(undefined, echo.headers['content-length']);
assert.equal('I💖🍕', echo.body);
});
});

it('can send a JSON body', function () {
var withJsonBody = {
baseUrl: defaultOptions.baseUrl,
Expand Down Expand Up @@ -75,6 +103,4 @@ describe('fetch: sending a body', function () {
echo.body);
});
});

it('can send a node ReadableStream');
});

0 comments on commit 4ed4471

Please sign in to comment.