Skip to content

Commit

Permalink
Fix node@16 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elbywan committed Jun 1, 2024
1 parent 4693837 commit 71aa327
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export const core: Wretch = {
headers(headerValues) {
const headers =
!headerValues ? {} :
Array.isArray(headerValues) ? Object.fromEntries(headerValues) :
"entries" in headerValues ? Object.fromEntries((headerValues as Headers).entries()) :
headerValues
Array.isArray(headerValues) ? Object.fromEntries(headerValues) :
"entries" in headerValues ? Object.fromEntries((headerValues as Headers).entries()) :
headerValues
return { ...this, _options: mix(this._options, { headers }) }
},
accept(headerValue) {
Expand Down Expand Up @@ -92,11 +92,11 @@ export const core: Wretch = {
let base = this.url(url).options({ method })
// "Jsonify" the body if it is an object and if it is likely that the content type targets json.
const contentType = extractContentType(base._options.headers)
const isFormDataInstance = body => {
const formData = this._config.polyfill("FormData", false)
return formData !== null && body instanceof formData
}
const jsonify = typeof body === "object" && !isFormDataInstance(body) && (!base._options.headers || !contentType || isLikelyJsonMime(contentType))
const formDataClass = this._config.polyfill("FormData", false)
const jsonify =
typeof body === "object" &&
!(formDataClass && body instanceof formDataClass) &&
(!base._options.headers || !contentType || isLikelyJsonMime(contentType))
base =
!body ? base :
jsonify ? base.json(body, contentType) :
Expand Down
2 changes: 1 addition & 1 deletion test/node/wretch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ describe("Wretch", function () {
false
);

let formData = new FormData()
let formData: any = new FormData()
formData.append("hello", "world")
formData.append("duck", "Muscovy")
formData.append("duckImage", fs.createReadStream(duckImagePath))
Expand Down

0 comments on commit 71aa327

Please sign in to comment.