blob: dd2e8818ab602157a398e7365a85154f5ff38054 (
plain) (
blame)
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
|
import { it, expect } from "bun:test";
import { sleepSync } from "bun";
it("sleepSync uses milliseconds", async () => {
const start = Date.now();
sleepSync(5);
const end = Date.now();
expect(end - start).toBeGreaterThanOrEqual(5);
expect(end - start).toBeLessThan(10);
});
it("sleepSync with no arguments throws", async () => {
expect(() => sleepSync()).toThrow();
});
it("sleepSync with non-numbers throws", async () => {
expect(() => sleepSync(true)).toThrow();
expect(() => sleepSync(false)).toThrow();
expect(() => sleepSync("hi")).toThrow();
expect(() => sleepSync({})).toThrow();
expect(() => sleepSync([])).toThrow();
expect(() => sleepSync(undefined)).toThrow();
expect(() => sleepSync(null)).toThrow();
});
it("sleepSync with negative number throws", async () => {
expect(() => sleepSync(-10)).toThrow();
});
it("can map with sleepSync", async () => {
[1, 2, 3].map(sleepSync);
});
|