-
-
Notifications
You must be signed in to change notification settings - Fork 156
/
formDataAppendFile.test.mjs
59 lines (47 loc) · 1.6 KB
/
formDataAppendFile.test.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// @ts-check
import "./test/polyfillFile.mjs";
import { ok, strictEqual } from "node:assert";
import { describe, it } from "node:test";
import formDataAppendFile from "./formDataAppendFile.mjs";
import assertBundleSize from "./test/assertBundleSize.mjs";
describe("Function `formDataAppendFile`.", { concurrency: true }, () => {
it("Bundle size.", async () => {
await assertBundleSize(
new URL("./formDataAppendFile.mjs", import.meta.url),
100,
);
});
it("`Blob` instance.", () => {
const formData = new FormData();
const fieldName = "a";
const fileType = "text/plain";
formDataAppendFile(
formData,
fieldName,
new Blob(["a"], { type: fileType }),
);
const formDataEntries = Array.from(formData.entries());
strictEqual(formDataEntries.length, 1);
strictEqual(formDataEntries[0][0], "a");
ok(typeof formDataEntries[0][1] === "object");
strictEqual(formDataEntries[0][1].name, "blob");
strictEqual(formDataEntries[0][1].type, fileType);
});
it("`File` instance.", () => {
const formData = new FormData();
const fieldName = "a";
const fileName = "a.txt";
const fileType = "text/plain";
formDataAppendFile(
formData,
fieldName,
new File(["a"], fileName, { type: fileType }),
);
const formDataEntries = Array.from(formData.entries());
strictEqual(formDataEntries.length, 1);
strictEqual(formDataEntries[0][0], "a");
ok(typeof formDataEntries[0][1] === "object");
strictEqual(formDataEntries[0][1].name, fileName);
strictEqual(formDataEntries[0][1].type, fileType);
});
});