28 lines
642 B
TypeScript
28 lines
642 B
TypeScript
import { describe, expect, test } from "bun:test"
|
|
|
|
import { parseDuration } from "./duration.ts"
|
|
|
|
describe("parseDuration", () => {
|
|
test("milliseconds", () => {
|
|
expect(parseDuration("500ms")).toBe(500)
|
|
})
|
|
|
|
test("seconds", () => {
|
|
expect(parseDuration("10s")).toBe(10000)
|
|
})
|
|
|
|
test("minutes", () => {
|
|
expect(parseDuration("1m")).toBe(60000)
|
|
})
|
|
|
|
test("fractional seconds", () => {
|
|
expect(parseDuration("1.5s")).toBe(1500)
|
|
})
|
|
|
|
test("invalid throws", () => {
|
|
expect(() => parseDuration("abc")).toThrow()
|
|
expect(() => parseDuration("10")).toThrow()
|
|
expect(() => parseDuration("10h")).toThrow()
|
|
})
|
|
})
|