aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Dylan Conway <35280289+dylan-conway@users.noreply.github.com> 2023-08-31 17:33:08 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-31 17:33:08 -0700
commitfef70f2473daefe242c80b9f3f34ef67396efaef (patch)
tree2f6dce4958d0a954115b6279deef418d9c8c340e /test
parentbd7262f037589a69be8b5fb2f705666309c32b86 (diff)
downloadbun-fef70f2473daefe242c80b9f3f34ef67396efaef.tar.gz
bun-fef70f2473daefe242c80b9f3f34ef67396efaef.tar.zst
bun-fef70f2473daefe242c80b9f3f34ef67396efaef.zip
get name if not provided in `FormData.append` (#4434)
* get file name from blob if not provided * add test * another test * format
Diffstat (limited to 'test')
-rw-r--r--test/js/web/html/FormData.test.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/js/web/html/FormData.test.ts b/test/js/web/html/FormData.test.ts
index c742bd33e..5e4861bc8 100644
--- a/test/js/web/html/FormData.test.ts
+++ b/test/js/web/html/FormData.test.ts
@@ -36,6 +36,36 @@ describe("FormData", () => {
expect(formData.getAll("foo")[0]).toBe("bar");
});
+ it("should get filename from file", async () => {
+ const blob = new Blob(["bar"]);
+ const formData = new FormData();
+ formData.append("foo", blob);
+ // @ts-expect-error
+ expect(formData.get("foo").name).toBeUndefined();
+ formData.append("foo2", new File([blob], "foo.txt"));
+ // @ts-expect-error
+ expect(formData.get("foo2").name).toBe("foo.txt");
+ });
+
+ it("should use the correct filenames", async () => {
+ const blob = new Blob(["bar"]) as any;
+ const form = new FormData();
+ form.append("foo", blob);
+ expect(blob.name).toBeUndefined();
+
+ let b1 = form.get("foo") as any;
+ expect(blob.name).toBeUndefined();
+ expect(b1.name).toBeUndefined();
+
+ form.set("foo", b1, "foo.txt");
+ expect(blob.name).toBeUndefined();
+ expect(b1.name).toBeUndefined();
+
+ b1 = form.get("foo") as Blob;
+ expect(blob.name).toBeUndefined();
+ expect(b1.name).toBe("foo.txt");
+ });
+
const multipartFormDataFixturesRawBody = [
{
name: "simple",