/** * Assert that a condition remains true for the whole timeout. * * @param {() => any} testfunc The test function. Must return `true` to signal success. * @param {Object} [options] Options (currently not visible in output due to typedoc bug) * @param {string} [options.message] Error message shown if the testfunc fails. * @param {number} [options.timeout] How long to wait, in milliseconds. * @param {number} [options.checkEvery] Intervals between checks, in milliseconds. */ export function assertAlways(testfunc: () => any, { message, timeout, checkEvery }?: { message?: string | undefined; timeout?: number | undefined; checkEvery?: number | undefined; } | undefined): Promise; /** * Assert that an asynchronously evaluated condition is eventually true. * * @param {() => Promise} testfunc The async test function. Must return `true` to signal success. * @param {{message?: string, timeout?: number, checkEvery?: number, crashOnError?: boolean}} [__namedParameters] Options (currently not visible in output due to typedoc bug) * @param {string?} message Error message shown if the condition never becomes true within the timeout. * @param {number?} timeout How long to wait, in milliseconds. * @param {number?} checkEvery Intervals between checks, in milliseconds. * @param {boolean?} crashOnError `true` (default): A thrown error/exception is an immediate failure. * `false`: A thrown error/exception is treated as if the test function returned false. */ export function assertAsyncEventually(testfunc: () => Promise, { message, timeout, checkEvery, crashOnError, }?: { message?: string | undefined; timeout?: number | undefined; checkEvery?: number | undefined; crashOnError?: boolean | undefined; } | undefined): Promise; /** * Assert that a condition is eventually true. * * @example * ```javascript * let called = false; * setTimeout(() => {called = true;}, 2000); * await assertEventually(() => called); * ``` * @param {() => any} testfunc The test function. Must return `true` to signal success. * @param {{message?: string, messageFunc?: () => string, timeout?: number, checkEvery?: number, crashOnError?: boolean}} [__namedParameters] Options (currently not visible in output due to typedoc bug) * @param {string?} message Error message shown if the condition never becomes true within the timeout. * @param {(() => string) ?} messageFunc A callable to generate the error message. If set, the message parameter is ignored. * @param {number?} timeout How long to wait, in milliseconds. * @param {number?} checkEvery Intervals between checks, in milliseconds. * @param {boolean?} crashOnError `true` (default): A thrown error/exception is an immediate failure. * `false`: A thrown error/exception is treated as if the test function returned false. */ export function assertEventually(testfunc: () => any, { message, messageFunc, timeout, checkEvery, crashOnError, }?: { message?: string | undefined; messageFunc?: (() => string) | undefined; timeout?: number | undefined; checkEvery?: number | undefined; crashOnError?: boolean | undefined; } | undefined): Promise; /** * Assert `x < y`. * @param {number|BigInt} x The ostensibly larger value. * @param {number|BigInt} y The ostensibly smaller value. * @param {string?} message Optional error message if the assertion does not hold. */ export function assertGreater(x: number | BigInt, y: number | BigInt, message?: string | null): void; /** * Assert `x >= y`. * @param {number|BigInt} x The ostensibly smaller or equal value. * @param {number|BigInt} y The ostensibly larger or equal value. * @param {string?} message Optional error message if the assertion does not hold. */ export function assertGreaterEqual(x: number | BigInt, y: number | BigInt, message?: string | null): void; /** * Assert that an HTTP response finished with the given status code. * * @example * ```javascript * const response = await fetch(config, 'https://foo.example/'); * await assertHttpStatus(response, 200); * // Or, the shorter form: * const shortResponse = await assertHttpStatus(fetch(config, 'https://foo.example/')); * ``` * @param {*|Promise<*>} response HTTP fetch response object, as gotten from `await `[["net_utils".fetch|`netutils.fetch`]]`(...)`, or the promise resolving to that (e.g. just `[["net_utils".fetch|`netutils.fetch`]]`(...)`). * @param {number?} expectedStatus The expected HTTP status (e.g. 201 for Created) * @param {{message?: string}} [__namedParameters] Options (currently not visible in output due to typedoc bug) * @param {string?} message Error message shown if the assertion fails. * @returns {*} The fetch response object. */ export function assertHttpStatus(response: any | Promise, expectedStatus?: number | null, { message }?: { message?: string | undefined; } | undefined): any; /** * Assert that a string is included in another, or object is included in an array. * * @example * ```javascript * assertIncludes('foobar', 'foo'); * assertIncludes([9, 5, 3], 5); * ``` * @param {string|array} haystack The thing to search in. * @param {string|array} needle The thing to search for. * @param {string?} message Optional error message if the assertion does not hold. */ export function assertIncludes(haystack: string | any, needle: string | any, message?: string | null): void; /** * Assert `x < y`. * @param {number|BigInt} x The ostensibly smaller value. * @param {number|BigInt} y The ostensibly larger value. * @param {string?} message Optional error message if the assertion does not hold. */ export function assertLess(x: number | BigInt, y: number | BigInt, message?: string | null): void; /** * Assert `x <= y`. * @param {number|BigInt} x The ostensibly smaller or equal value. * @param {number|BigInt} y The ostensibly larger or equal value. * @param {string?} message Optional error message if the assertion does not hold. */ export function assertLessEqual(x: number | BigInt, y: number | BigInt, message?: string | null): void; /** * Assert that a string is not included in another, or object is not included in an array. * * @example * ```javascript * assertNotIncludes('foobar', 'xxx'); * assertNotIncludes([9, 5, 3], 2); * ``` * @template T * @param {T[]} haystack The thing to search in. * @param {T} needle The thing to search for. * @param {string?} message Optional error message if the assertion does not hold. */ export function assertNotIncludes(haystack: T[], needle: T, message?: string | null): void; /** * Assert that a value is a Number or BigInt. * @param x {number|BigInt} The value to check. */ export function assertNumeric(x: number | BigInt, message?: any): void; /** * Assert function with a message that is generated on demand. * @example * ```javascript * lazyAssert(obj?.foo?.bar, () => `Object is missing foo.bar. Full object: ${JSON.stringify(obj)}`); * ``` * @param {boolean} value The value to be asserted to be true. * @param {() => string} makeMessage Function to generate the error message, should the value be false. */ export function lazyAssert(value: boolean, makeMessage: () => string): void; /** * Wait until a function returns a result that is truthy * @param {() => any} testfunc * @param {{timeout?: number, checkEvery?: number, message?: string}} [options] */ export function waitFor(testfunc: () => any, options?: { timeout?: number | undefined; checkEvery?: number | undefined; message?: string | undefined; } | undefined): Promise; /** * Wait until a function doesn't throw anymore. * @param {() => any} testfunc * @param {{timeout?: number, checkEvery?: number, message?: string}} [options] */ export function waitForPass(testfunc: () => any, options?: { timeout?: number | undefined; checkEvery?: number | undefined; message?: string | undefined; } | undefined): Promise;