Files
hermes-agent/apps/desktop/src/lib/with-timeout.test.ts
T
2026-08-25 22:51:31 -07:00

25 lines
666 B
TypeScript

import { describe, expect, it, vi } from 'vitest'
import { withTimeout } from './with-timeout'
describe('withTimeout', () => {
it('rejects with an onTimeout exception instead of letting it escape the timer callback', async () => {
vi.useFakeTimers()
try {
const callbackFailure = new Error('abort callback failed')
const result = withTimeout(new Promise<never>(() => undefined), 10, 'work timed out', () => {
throw callbackFailure
})
const rejection = expect(result).rejects.toBe(callbackFailure)
await vi.advanceTimersByTimeAsync(10)
await rejection
} finally {
vi.useRealTimers()
}
})
})