Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Aug 5, 2021
1 parent 0db311b commit 7ec6fbc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
9 changes: 7 additions & 2 deletions lib/api/api-fetch/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const util = require('../../core/util')
const { finished } = require('stream')
const { ReadableStream, CountQueuingStrategy } = require('stream/web')
const { AbortError, InvalidArgumentError } = require('../../core/errors')
const { AbortError } = require('../../core/errors')

// https://fetch.spec.whatwg.org/#concept-bodyinit-extract
function extractBody (body) {
Expand All @@ -26,8 +26,13 @@ function extractBody (body) {
} else if (
body instanceof ArrayBuffer ||
ArrayBuffer.isView(body) ||
util.isBuffer(body)
util.isBuffer(body) ||
body instanceof DataView
) {
if (body instanceof DataView) {
// TODO: Blob doesn't seem to work with DataView?
body = body.buffer
}
return [{
source: body
}, null]
Expand Down
4 changes: 2 additions & 2 deletions test/node-fetch/external-encoding.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// import chai from 'chai'
// import { fetch } from '../../index.js'
// const chai = require('chai')
// const { fetch } = require('../../index.js')

// const { expect } = chai

Expand Down
14 changes: 7 additions & 7 deletions test/node-fetch/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ describe('Response', () => {
})
})

// it('should support DataView as body', () => {
// const encoder = new TextEncoder()
// const res = new Response(new DataView(encoder.encode('a=1').buffer))
// return res.text().then(result => {
// expect(result).to.equal('a=1')
// })
// })
it('should support DataView as body', () => {
const encoder = new TextEncoder()
const res = new Response(new DataView(encoder.encode('a=1').buffer))
return res.text().then(result => {
expect(result).to.equal('a=1')
})
})

it('should default to null as body', () => {
const res = new Response()
Expand Down

0 comments on commit 7ec6fbc

Please sign in to comment.