Improve Body spec compliance when body is null
This commit is contained in:
parent
9d3cc52601
commit
64e239b092
|
@ -79,6 +79,11 @@ export default class Body {
|
|||
|
||||
this[DISTURBED] = true;
|
||||
|
||||
// body is null
|
||||
if (!this.body) {
|
||||
return Body.Promise.resolve(new Buffer(0));
|
||||
}
|
||||
|
||||
// body is string
|
||||
if (typeof this.body === 'string') {
|
||||
return Body.Promise.resolve(convertBody([new Buffer(this.body)], this.headers));
|
||||
|
|
|
@ -17,7 +17,7 @@ import Body, { clone } from './body';
|
|||
* @return Void
|
||||
*/
|
||||
export default class Response extends Body {
|
||||
constructor(body, opts = {}) {
|
||||
constructor(body = null, opts = {}) {
|
||||
super(body, opts);
|
||||
|
||||
this.url = opts.url;
|
||||
|
|
|
@ -1427,6 +1427,14 @@ describe('node-fetch', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should default to null as body', function() {
|
||||
const res = new Response();
|
||||
expect(res.body).to.equal(null);
|
||||
return res.text().then(result => {
|
||||
expect(result).to.equal('');
|
||||
});
|
||||
});
|
||||
|
||||
it('should default to 200 as status code', function() {
|
||||
const res = new Response(null);
|
||||
expect(res.status).to.equal(200);
|
||||
|
|
Loading…
Reference in New Issue