aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/bun.js/sleep.js2
-rw-r--r--test/bun.js/sleepSync.test.ts32
2 files changed, 33 insertions, 1 deletions
diff --git a/test/bun.js/sleep.js b/test/bun.js/sleep.js
index 080597424..1ec79e79d 100644
--- a/test/bun.js/sleep.js
+++ b/test/bun.js/sleep.js
@@ -1,4 +1,4 @@
-const interval = 0.01;
+const interval = 10;
const now = performance.now();
console.time("Slept");
Bun.sleepSync(interval);
diff --git a/test/bun.js/sleepSync.test.ts b/test/bun.js/sleepSync.test.ts
new file mode 100644
index 000000000..dd2e8818a
--- /dev/null
+++ b/test/bun.js/sleepSync.test.ts
@@ -0,0 +1,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);
+});