Add unit tests for util functions: iife, lazy, timeout (#3791)

This commit is contained in:
James Alexander
2025-11-03 09:24:45 -05:00
committed by GitHub
parent 573ffe186b
commit 37a6b5177e
3 changed files with 107 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
import { describe, expect, test } from "bun:test"
import { iife } from "../../src/util/iife"
describe("util.iife", () => {
test("should execute function immediately and return result", () => {
let called = false
const result = iife(() => {
called = true
return 42
})
expect(called).toBe(true)
expect(result).toBe(42)
})
test("should work with async functions", async () => {
let called = false
const result = await iife(async () => {
called = true
return "async result"
})
expect(called).toBe(true)
expect(result).toBe("async result")
})
test("should handle functions with no return value", () => {
let called = false
const result = iife(() => {
called = true
})
expect(called).toBe(true)
expect(result).toBeUndefined()
})
})