-
-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathUpload.test.mjs
More file actions
62 lines (43 loc) · 1.57 KB
/
Copy pathUpload.test.mjs
File metadata and controls
62 lines (43 loc) · 1.57 KB
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
60
61
62
// @ts-check
/** @import { FileUpload } from "./processRequest.mjs" */
import { ok, rejects, strictEqual } from "node:assert";
import { suite, test } from "node:test";
import Upload from "./Upload.mjs";
suite(
"Class `Upload`.",
{
concurrency: true,
},
() => {
test("Resolving a file.", async () => {
const upload = new Upload();
ok(upload.promise instanceof Promise);
strictEqual(typeof upload.resolve, "function");
const file = /** @type {FileUpload} */ ({});
upload.resolve(file);
const resolved = await upload.promise;
strictEqual(resolved, file);
strictEqual(upload.file, file);
});
test("Handled rejection.", async () => {
const upload = new Upload();
ok(upload.promise instanceof Promise);
strictEqual(typeof upload.reject, "function");
const error = new Error("Message.");
upload.reject(error);
// This is the safe way to check the promise status, see:
// https://github.com/nodejs/node/issues/31392#issuecomment-575451230
await rejects(Promise.race([upload.promise, Promise.resolve()]), error);
});
test("Unhandled rejection.", async () => {
const upload = new Upload();
ok(upload.promise instanceof Promise);
strictEqual(typeof upload.reject, "function");
const error = new Error("Message.");
upload.reject(error);
// Rely on the Node.js v15+ CLI option default
// `--unhandled-rejections=throw` exiting the process with an error if the
// unhandled rejection isn’t silenced as intended.
});
},
);