-
-
Notifications
You must be signed in to change notification settings - Fork 687
Expand file tree
/
Copy pathjson.test.js
More file actions
42 lines (35 loc) · 974 Bytes
/
json.test.js
File metadata and controls
42 lines (35 loc) · 974 Bytes
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
import { createServer, request as _request } from "node:http";
import assert, { deepStrictEqual, strictEqual } from "node:assert";
import formidable from "../../src/index.js";
const testData = {
numbers: [1, 2, 3, 4, 5],
nested: { key: "val" },
};
const PORT = 13535;
test("json", (done) => {
const server = createServer((req, res) => {
const form = formidable({});
form.parse(req, (err, fields) => {
strictEqual(Object.getPrototypeOf(fields), null);
deepStrictEqual({ ...fields }, {
numbers: [1, 2, 3, 4, 5],
nested: { key: "val" },
});
res.end();
server.close();
done();
});
});
server.listen(PORT, (err) => {
assert(!err, "should not have error, but be falsey");
const request = _request({
port: PORT,
method: "POST",
headers: {
"Content-Type": "application/json",
},
});
request.write(JSON.stringify(testData));
request.end();
});
});