import { expect, tap } from '@git.zone/tstest/tapbundle'; import * as smartdelay from '../ts/index.js'; tap.test('.delayFor should delay async', async () => { let timePassed = false; setTimeout(() => { timePassed = true; }, 10); await smartdelay.delayFor(20); expect(timePassed).toBeTrue(); }); tap.test('.delayForRandom should pass through values', async () => { const originalRandom = Math.random; Math.random = () => 0; try { const result = await smartdelay.delayForRandom(1, 2, 'random-result'); expect(result).toEqual('random-result'); } finally { Math.random = originalRandom; } }); tap.test('.delayFor should pass on a type', async () => { const hey = 'heyThere'; const stringArg = await smartdelay.delayFor(1, hey); expect(stringArg).toEqual('heyThere'); }); tap.test('smartdelay.Timeout', async () => { const timeout = new smartdelay.Timeout(1); await timeout.promise; }); tap.test('smartdelay.Timeout should cancel', async () => { const timeout = new smartdelay.Timeout(60000); timeout.cancel(); expect(timeout.getTimeLeft()).toBeGreaterThan(0); }); export default tap.start();