UNPKG

@jrc03c/js-math-tools

Version:
18 lines (14 loc) 494 B
import { expect, test } from "@jrc03c/fake-jest" import { pause, pauseSync } from "@jrc03c/pause" import { time } from "./time.mjs" test("tests that the `time` function works correctly", async () => { for (let i = 0; i < 10; i++) { const ms = Math.random() * 250 // sync const t1 = time(() => pauseSync(ms)) expect(Math.abs(t1 - ms)).toBeLessThan(10) // async const t2 = await time(async () => await pause(ms)) expect(Math.abs(t2 - ms)).toBeLessThan(10) } })