Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162/** Tests for `withTimeout`. @module */
import { describe, expect, it,} from '@monochromatic-dev/module-test/ts';
import { withTimeout, } from '../dist/final/neutral/index.mjs';
await describe({ name: withTimeout.name, children: [ it({ name: 'resolves when promise settles in time', fn: async () => { const DELAY = 10; const TIMEOUT = 200; const EXPECTED = 'done';
const result = await withTimeout({ promise: new Promise(function resolveAfterDelay(resolve,) { setTimeout(function onDelay() { resolve(EXPECTED,); }, DELAY,); },), ms: TIMEOUT, label: 'fast', },);
expect(result,).toBe(EXPECTED,); }, },),
it({ name: 'rejects with descriptive message on timeout', fn: async () => { const DELAY = 300; const TIMEOUT = 10;
const rejection = withTimeout({ promise: new Promise(function resolveAfterDelay(resolve,) { setTimeout(resolve, DELAY,); },), ms: TIMEOUT, label: 'timeout-label', },);
await expect(rejection,).rejects.toBeInstanceOf(Error,); await expect(rejection,).rejects.toHaveProperty( 'message', `Timed out after ${String(TIMEOUT,)}ms: timeout-label`, ); }, },), ],},);