UNPKG

assert-helpers

Version:

Common utilities and helpers to make testing assertions easier

205 lines 10.6 kB
/** Type for a callback that receives an optional error as the first argument */ type Errback = (error?: Error) => void; /** * Alias for setTimeout with paramaters reversed. * @param delay - The delay in milliseconds before executing the function * @param fn - The function to execute after the delay * @returns The timer ID returned by setTimeout */ export declare function wait(delay: number, fn: (...args: any[]) => void): NodeJS.Timeout; /** * Whether or not we are running in the node environment * @returns True if running in Node.js, false otherwise */ export declare function isNode(): boolean; /** * Whether or not stdout and stderr are interactive. * @returns True if both stdout and stderr are TTY, false otherwise */ export declare function isTTY(): boolean; /** * Convert a value to its boolean equivalent * @param value - The value to convert to boolean * @returns The boolean equivalent of the value, or null if undetermined */ export declare function bool(value: any): boolean | null; /** * Whether or not colors are desired on this environment * @returns True if colors should be used, false otherwise */ export declare function useColors(): boolean; /** * Applies the color to the value if desired * @param value - The value to colorize * @param color - The color function to apply * @returns The colorized string if colors are enabled, otherwise the string value */ export declare function color(value: any, color: (input: any) => string): string; /** * Return a stringified version of the value with indentation and colors where applicable. * Colors will be applied if the environment supports it (--no-colors not present and TTY). * For the available options, refer to https://nodejs.org/dist/latest-v14.x/docs/api/util.html#util_util_inspect_object_options for Node.js * @param value - The value to inspect and stringify * @param opts - Additional options for the inspection * @returns The stringified and optionally colorized representation of the value */ export declare function inspect(value: any, opts?: any): string; /** * Log the inspected values of each of the arguments to stdout * @param args - The values to log */ export declare function log(...args: any): void; /** * Output a comparison of the failed result to stderr * @param actual - The actual value that was received * @param expected - The expected value * @param error - The error that occurred during comparison */ export declare function logComparison(actual: any, expected: any, error: Error | string | any): void; /** * Same as assert.strictEqual in that it performs a strict equals check, but if a failure occurs it will output detailed information * @param actual - The actual value to compare * @param expected - The expected value to compare against * @param testName - The name of the test for error reporting * @param next - Optional callback to call with any error */ export declare function equal(actual: any, expected: any, testName?: string, next?: Errback): void | never; /** * Is greater than or equal to * @param actual - The actual value to compare * @param expected - The expected value to compare against * @param testName - The name of the test for error reporting * @param next - Optional callback to call with any error */ export declare function gte(actual: any, expected: any, testName?: string, next?: Errback): void | never; /** * Is less than or equal to * @param actual - The actual value to compare * @param expected - The expected value to compare against * @param testName - The name of the test for error reporting * @param next - Optional callback to call with any error */ export declare function lte(actual: any, expected: any, testName?: string, next?: Errback): void | never; /** * Is greater than * @param actual - The actual value to compare * @param expected - The expected value to compare against * @param testName - The name of the test for error reporting * @param next - Optional callback to call with any error */ export declare function gt(actual: any, expected: any, testName?: string, next?: Errback): void | never; /** * Is less than * @param actual - The actual value to compare * @param expected - The expected value to compare against * @param testName - The name of the test for error reporting * @param next - Optional callback to call with any error */ export declare function lt(actual: any, expected: any, testName?: string, next?: Errback): void | never; /** * Ensure what is passed is undefined, otherwise fail and output what it is * @param actual - The actual value to check * @param testName - The name of the test for error reporting * @param next - Optional callback to call with any error */ export declare function undef(actual: any, testName?: string, next?: Errback): void; /** * Ensure what is passed is undefined or null, otherwise fail and output what it is * @param actual - The actual value to check * @param testName - The name of the test for error reporting * @param next - Optional callback to call with any error */ export declare function nullish(actual: any, testName?: string, next?: Errback): void; /** * Same as assert.deepStrictEqual in that it performs a deep strict equals check, but if a failure occurs it will output detailed information * @param actual - The actual value to compare * @param expected - The expected value to compare against * @param testName - The name of the test for error reporting * @param next - Optional callback to call with any error */ export declare function deepEqual(actual: any, expected: any, testName?: string, next?: Errback): void | never; /** * Checks to see if the actual result contains the expected result . * @param actual - The actual value to check for containment * @param expected - The expected value that should be contained * @param testName - The name of the test for error reporting * @param next - Optional callback to call with any error */ export declare function contains(actual: any, expected: any, testName?: string, next?: Errback): void | never; /** * Checks to see if the actual result does not contain the expected result . * @param actual - The actual value to check for non-containment * @param expected - The expected value that should not be contained * @param testName - The name of the test for error reporting * @param next - Optional callback to call with any error */ export declare function notContains(actual: any, expected: any, testName?: string, next?: Errback): void | never; /** * Checks to see if an error was as expected, if a failure occurs it will output detailed information * @param actualError - The actual error that was thrown * @param expectedError - The expected error to match against * @param testName - The name of the test for error reporting * @param next - Optional callback to call with any error */ export declare function errorEqual(actualError: any, expectedError: any, testName?: string, next?: Errback): void | never; /** * Generate a callback that will return the specified value. * @param value - The value to return from the callback * @returns A function that returns the specified value */ export declare function returnViaCallback(value: any): () => typeof value; /** * Generate a callback that will receive a completion callback whcih it will call with the specified result after the specified delay. * @param value - The value to pass to the completion callback * @param delay - The delay in milliseconds before calling the completion callback * @returns A function that takes a completion callback and calls it with the value after the delay */ export declare function completeViaCallback(value: any, delay?: number): (complete: (error: null, result: typeof value) => void) => void; /** * Generate a callback that will receive a completion callback which it will call with the passed error after the specified delay. * @param error - The error to pass to the completion callback * @param delay - The delay in milliseconds before calling the completion callback * @returns A function that takes a completion callback and calls it with the error after the delay */ export declare function errorViaCallback(error: Error | string, delay?: number): (complete: (error: Error | string) => void) => void; /** * Generate a callback that return an error instance with the specified message/error. * @param error - The error message or Error instance to return * @returns A function that returns an Error instance */ export declare function returnErrorViaCallback(error?: Error | string): () => Error; /** * Generate a callback that throw an error instance with the specified message/error. * @param error - The error message or Error instance to throw * @returns A function that throws an Error instance */ export declare function throwErrorViaCallback(error?: Error | string): () => never; /** * Generate a callback that will check the arguments it received with the arguments specified, if a failure occurs it will output detailed information. * @param expected - The expected arguments to compare against * @returns A function that compares received arguments with expected arguments */ export declare function expectViaCallback(...expected: any): (...actual: any) => void; /** * Generate a callback that will check its error (the actual error) against the passed error (the expected error). * If a failure occurs it will output detailed information. * @param expected - The expected error to match against * @param testName - The name of the test for error reporting * @param next - Optional callback to call with any error * @returns A function that compares an actual error with the expected error */ export declare function expectErrorViaCallback(expected: Error | string, testName?: string, next?: Errback): (actual: Error | string) => void; /** * Expect the passed function to throw an error at some point. * @param expected - The expected error to match against * @param fn - The function that should throw an error * @param testName - The name of the test for error reporting * @param next - Optional callback to call with any error */ export declare function expectThrowViaFunction(expected: Error | string, fn: () => never, testName?: string, next?: Errback): void; /** @deprecated Use {@link expectErrorViaFunction} instead */ export declare function expectErrorViaFunction(): never; /** @deprecated Use {@link expectErrorViaFunction} instead */ export declare function expectFunctionToThrow(): never; export {}; //# sourceMappingURL=index.d.ts.map