We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 03672e4 commit 7de978bCopy full SHA for 7de978b
lib/sleep.function.spec.ts
@@ -0,0 +1,16 @@
1
+import { sleep } from "./sleep.function";
2
+
3
+describe("sleep", () => {
4
+ it("should resolve after x ms", async () => {
5
+ // GIVEN
6
+ const timeout = 500;
7
8
+ // WHEN
9
+ const before = Date.now();
10
+ await sleep(timeout);
11
+ const after = Date.now();
12
13
+ // THEN
14
+ expect(after - before).toBeGreaterThanOrEqual(timeout);
15
+ });
16
+});
lib/sleep.function.ts
@@ -0,0 +1,3 @@
+export const sleep = async (ms: number) => {
+ return new Promise(resolve => setTimeout(resolve, ms));
+};
0 commit comments