Skip to content

Commit ff66152

Browse files
committed
test(core/utils): add unit test for callUntilEnd, callPromiseUntilEnd
1 parent f5c60c1 commit ff66152

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { callPromiseUntilEnd, callUntilEnd } from "@/main";
2+
import { expect, test } from "vitest";
3+
4+
test("Call until end", async () => {
5+
const startT = Date.now();
6+
let i = 0;
7+
await callUntilEnd(() => {
8+
expect(Date.now() - startT).toBeGreaterThanOrEqual(100 * i);
9+
return ++i === 10;
10+
}, 100);
11+
12+
expect(Date.now() - startT).toBeGreaterThanOrEqual(1000);
13+
expect(i).toBe(10);
14+
});
15+
16+
test("Call promise until end", async () => {
17+
const startT = Date.now();
18+
let i = 0;
19+
await callPromiseUntilEnd(async () => {
20+
return new Promise((resolve) =>
21+
setTimeout(() => {
22+
i++;
23+
expect(Date.now() - startT).toBeGreaterThanOrEqual(100 * i * 2);
24+
console.log(Date.now() - startT, i);
25+
26+
resolve(i >= 10);
27+
}, 100)
28+
);
29+
}, 100);
30+
31+
expect(Date.now() - startT).toBeGreaterThanOrEqual(2000);
32+
expect(i).toBe(10);
33+
});

0 commit comments

Comments
 (0)