-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(core/utils): add unit test for callUntilEnd, callPromiseUntilEnd
- Loading branch information
1 parent
f5c60c1
commit ff66152
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { callPromiseUntilEnd, callUntilEnd } from "@/main"; | ||
import { expect, test } from "vitest"; | ||
|
||
test("Call until end", async () => { | ||
const startT = Date.now(); | ||
let i = 0; | ||
await callUntilEnd(() => { | ||
expect(Date.now() - startT).toBeGreaterThanOrEqual(100 * i); | ||
return ++i === 10; | ||
}, 100); | ||
|
||
expect(Date.now() - startT).toBeGreaterThanOrEqual(1000); | ||
expect(i).toBe(10); | ||
}); | ||
|
||
test("Call promise until end", async () => { | ||
const startT = Date.now(); | ||
let i = 0; | ||
await callPromiseUntilEnd(async () => { | ||
return new Promise((resolve) => | ||
setTimeout(() => { | ||
i++; | ||
expect(Date.now() - startT).toBeGreaterThanOrEqual(100 * i * 2); | ||
console.log(Date.now() - startT, i); | ||
|
||
resolve(i >= 10); | ||
}, 100) | ||
); | ||
}, 100); | ||
|
||
expect(Date.now() - startT).toBeGreaterThanOrEqual(2000); | ||
expect(i).toBe(10); | ||
}); |