generated from ayame113/deno_deploy_template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_test.ts
94 lines (85 loc) · 2.04 KB
/
mod_test.ts
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import {
assertEquals,
assertRejects,
} from "https://deno.land/[email protected]/testing/asserts.ts";
import { flakyTest } from "./mod.ts";
Deno.test("not throws", async (t) => {
let count = 0;
await flakyTest(() => {
count++;
})(t);
assertEquals(count, 1);
});
Deno.test("throws once", async (t) => {
let count = 0;
await flakyTest(() => {
count++;
if (count < 2) {
throw new Error("throws once");
}
})(t);
assertEquals(count, 2);
});
Deno.test("throws twice", async (t) => {
let count = 0;
await flakyTest(() => {
count++;
if (count < 3) {
throw new Error("throws once");
}
})(t);
assertEquals(count, 3);
});
Deno.test("throws three times", async (t) => {
let count = 0;
await assertRejects(async () => {
await flakyTest(() => {
count++;
if (count < 4) {
throw new Error("throws once");
}
})(t);
}, AggregateError);
assertEquals(count, 3);
});
Deno.test("throws three times, try 4 times", async (t) => {
let count = 0;
await flakyTest(() => {
count++;
if (count < 4) {
throw new Error("throws once");
}
}, { count: 4 })(t);
assertEquals(count, 4);
});
Deno.test("set func name", () => {
const f = flakyTest(function __name__() {});
assertEquals(f.name, "__name__");
});
Deno.test("not throws with async function", async (t) => {
let count = 0;
await flakyTest(async () => {
count++;
await Promise.resolve();
})(t);
assertEquals(count, 1);
});
Deno.test("throws three times with async function", async (t) => {
let count = 0;
await assertRejects(async () => {
await flakyTest(async () => {
count++;
await Promise.reject();
})(t);
}, AggregateError);
assertEquals(count, 3);
});
Deno.test({
name: "overload_1",
fn: flakyTest(() => {}),
});
Deno.test("overload_2", flakyTest(() => {}));
Deno.test(flakyTest(function overload_3() {}));
Deno.test("overload_4", {}, flakyTest(() => {}));
Deno.test({ name: "overload_5" }, flakyTest(() => {}));
Deno.test({}, flakyTest(function overload_6() {}));