UNPKG

@augment-vir/assert

Version:

A collection of assertions for test and production code alike.

60 lines (59 loc) 2.89 kB
import { type AnyFunction, type MaybePromise, type NarrowToExpected, type PartialWithUndefined, type RemoveFirstTupleEntry, type RemoveLastTupleEntry, type RequiredAndNotNull } from '@augment-vir/core'; import { type AnyDuration } from '@date-vir/duration'; import { type AssertFunction } from './assert-function.js'; /** * Options for configuring the timing of `waitUntil`. * * @category Assert : Util * @category Package : @augment-vir/assert * @package [`@augment-vir/assert`](https://www.npmjs.com/package/@augment-vir/assert) */ export type WaitUntilOptions = PartialWithUndefined<{ /** * The duration between attempts. * * @default {milliseconds: 100} */ interval: AnyDuration; /** * The maximum duration to keep trying. If the `waitUntil` expectations are still not met by * this time, an {@link AssertionError} will be thrown. * * @default {seconds: 10} */ timeout: AnyDuration; }>; export declare const defaultWaitUntilOptions: RequiredAndNotNull<WaitUntilOptions>; export declare function executeWaitUntil<const Assert extends AssertFunction<any>>(this: void, assert: AssertFunction<any>, rawArgs: unknown[], requireSynchronousResult: boolean): Promise<ReturnType<WaitUntilFunction<Assert>>>; export type WaitUntilOverridesBase<Keys extends PropertyKey = string> = Readonly<Partial<Record<Keys, AnyFunction | undefined>>>; export type WaitUntilFunctionParameters<Assert extends AssertFunction<any>, Input> = [ ...RemoveFirstTupleEntry<RemoveLastTupleEntry<Parameters<Assert>>>, () => MaybePromise<Input> ]; export type WaitUntilFunction<Assert extends AssertFunction<any>> = Assert extends AssertFunction<infer Guard> ? <Input extends Parameters<Assert>[0]>(this: void, ...params: [ ...WaitUntilFunctionParameters<Assert, Input>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined ]) => Promise<NarrowToExpected<Input, Guard>> : never; export declare function createWaitUntil<const Assert extends AssertFunction<any>>(assert: Assert, requireSynchronousResult?: boolean): WaitUntilFunction<Assert>; export declare function parseWaitUntilArgs(rawArgs: unknown[]): { callback: AnyFunction; options: RequiredAndNotNull<PartialWithUndefined<{ /** * The duration between attempts. * * @default {milliseconds: 100} */ interval: AnyDuration; /** * The maximum duration to keep trying. If the `waitUntil` expectations are still not met by * this time, an {@link AssertionError} will be thrown. * * @default {seconds: 10} */ timeout: AnyDuration; }>>; extraAssertionArgs: unknown[]; failureMessage: string | undefined; }; export declare function parseWaitUntilOptions(rawOptions: WaitUntilOptions | undefined): RequiredAndNotNull<WaitUntilOptions>;