Skip to content

Commit

Permalink
Merge pull request #190 from anzharip/fix/typing-update-from-busboy
Browse files Browse the repository at this point in the history
fix: typing update from busboy
  • Loading branch information
anzharip authored Nov 1, 2021
2 parents b31bb72 + 5606434 commit 56430c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ParsedMultipartFormData } from "./types/parsed-multipart-form-data.type
import { Config } from "./types/config.type";

export default async function parseMultipartFormData(
request: HttpRequest & { headers: { "content-type": string } },
request: HttpRequest,
options?: Config
): Promise<ParsedMultipartFormData> {
return new Promise((resolve, reject) => {
Expand All @@ -16,9 +16,14 @@ export default async function parseMultipartFormData(

let busboy;
if (options) {
busboy = new Busboy({ headers: request.headers, ...options });
busboy = new Busboy({
headers: (request.headers as unknown) as Busboy.BusboyHeaders,
...options,
});
} else {
busboy = new Busboy({ headers: request.headers });
busboy = new Busboy({
headers: (request.headers as unknown) as Busboy.BusboyHeaders,
});
}

busboy.on(
Expand Down
9 changes: 8 additions & 1 deletion test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from "fs";
import parseMultipartFormData from "../src/index";

describe("index.js", () => {
let request: HttpRequest & { headers: { "content-type": string } };
let request: HttpRequest;

beforeEach(async () => {
const file1 = fs.readFileSync("test/fixture/dummy-data.json");
Expand Down Expand Up @@ -50,6 +50,13 @@ describe("index.js", () => {
}).rejects.toThrow();
});

it("should reject the promise due to missing content-type", async () => {
delete request.headers["content-type"];
expect(async () => {
await parseMultipartFormData(request);
}).rejects.toThrow();
});

it("should accept options parameter, parse only one field", async () => {
const { fields } = await parseMultipartFormData(request, {
limits: { fields: 1 },
Expand Down

0 comments on commit 56430c7

Please sign in to comment.