import { IEqualityComparer } from './Equality/IEqualityComparer'; import { Constructor } from './Constructor'; import { RecursivePartial } from './RecursivePartial'; declare type ErrorValidatorPredicate = (value: T) => boolean; declare type ErrorValidatorMap = { readonly [index: string]: any; }; /** * Assertion class designed for unit testing */ export declare class Assert { /** * Tests if value is not undefined. * * @param value The value to test. * @param messageOrError Optional custom text or error to report in the case of failure. */ defined(value: T, messageOrError?: string | Error): void; /** * Tests if value is undefined. * * @param value The value to test. * @param messageOrError Optional custom text or error to report in the case of failure. */ undefined(value: T, messageOrError?: string | Error): void; /** * Tests if value is true. * * @param value The value to test. * @param messageOrError Optional custom text or error to report in the case of failure. */ true(value: boolean, messageOrError?: string | Error): void; /** * Tests if value is truthy. * * @param value The value to test. * @param messageOrError Optional custom text or error to report in the case of failure. */ truthy(value: T, messageOrError?: string | Error): void; /** * Tests if value is false. * * @param value The value to test. * @param messageOrError Optional custom text or error to report in the case of failure. */ false(value: boolean, messageOrError?: string | Error): void; /** * Tests if value is falsy. * * @param value The value to test. * @param messageOrError Optional custom text or error to report in the case of failure. */ falsy(value: T, messageOrError?: string | Error): void; /** * Throws an AssertionError with the provided error message or a default error message. * * @param actual The actual value to evaluate. * @param expected The expected value. * @param messageOrError Optional custom text or error to report in the case of failure. * @param operator */ fail(actual: T, expected: T, messageOrError?: string | Error, operator?: string): void; /** * Tests equality between the actual and expected parameters. * * @param actual The actual value to evaluate. * @param expected The expected value. * @param messageOrError Optional custom text or error to report in the case of failure. * @param equalityComparer The equality comparer to use. */ equal(actual: T, expected: T, messageOrError?: string | Error, equalityComparer?: IEqualityComparer): void; /** * Tests equality between the actual and expected parameters. * * @param actual The actual value to evaluate. * @param expected The expected value. * @param equalityComparer The equality comparer to use. */ equal(actual: T, expected: T, equalityComparer?: IEqualityComparer): void; /** * Tests inequality between the actual and expected parameters. * * @param actual The actual value to evaluate. * @param expected The expected value. * @param messageOrError Optional custom text or error to report in the case of failure. * @param equalityComparer The equality comparer to use. */ notEqual(actual: T, expected: T, messageOrError?: string | Error, equalityComparer?: IEqualityComparer): void; /** * Tests inequality between the actual and expected parameters. * * @param actual The actual value to evaluate. * @param expected The expected value. * @param equalityComparer The equality comparer to use. */ notEqual(actual: T, expected: T, equalityComparer?: IEqualityComparer): void; /** * Tests equality between the actual and expected parameters using value equality. * * @param actual The actual value to evaluate. * @param expected The expected value. * @param messageOrError Optional custom text or error to report in the case of failure. */ valueEqual(actual: T, expected: T, errorOrMessage?: string | Error): void; /** * Tests inequality between the actual and expected parameters using value equality. * * @param actual The actual value to evaluate. * @param expected The expected value. * @param messageOrError Optional custom text or error to report in the case of failure. */ notValueEqual(actual: T, expected: T, errorOrMessage?: string | Error): void; /** * Tests equality between the actual and expected parameters using structural equality. * * @param actual The actual value to evaluate. * @param expected The expected value. * @param messageOrError Optional custom text or error to report in the case of failure. */ structuralEqual(actual: T, expected: T, messageOrError?: string | Error): void; /** * Tests inequality between the actual and expected parameters using structural equality. * * @param actual The actual value to evaluate. * @param expected The expected value. * @param messageOrError Optional custom text or error to report in the case of failure. */ notStructuralEqual(actual: T, expected: T, messageOrError?: string | Error): void; /** * Tests partial equality between the actual and expected parameters using structural equality. * * @param actual The actual value to evaluate. * @param expected The expected value. * @param messageOrError Optional custom text or error to report in the case of failure. */ partialStructuralEqual(actual: T, expected: RecursivePartial, messageOrError?: string | Error): void; /** * Tests partial inequality between the actual and expected parameters using structural equality. * * @param actual The actual value to evaluate. * @param expected The expected value. * @param messageOrError Optional custom text or error to report in the case of failure. */ notPartialStructuralEqual(actual: T, expected: RecursivePartial, messageOrError?: string | Error): void; /** * Tests sequential equality between the actual and expected iterables. * * @param actual The actual value to evaluate. * @param expected The expected value. * @param messageOrError Optional custom text or error to report in the case of failure. * @param equalityComparer Optional equality comparer to use to compare items in the iterables. */ sequenceEqual(actual: Iterable, expected: Iterable, messageOrError?: string | Error, equalityComparer?: IEqualityComparer): void; /** * Tests sequential equality between the actual and expected iterables. * * @param actual The actual value to evaluate. * @param expected The expected value. * @param equalityComparer Optional equality comparer to use to compare items in the iterables. */ sequenceEqual(actual: Iterable, expected: Iterable, equalityComparer?: IEqualityComparer): void; /** * Tests sequential inequality between the actual and expected iterables. * * @param actual The actual value to evaluate. * @param expected The expected value. * @param messageOrError Optional custom text or error to report in the case of failure. * @param equalityComparer Optional equality comparer to use to compare items in the iterables. */ notSequenceEqual(actual: Iterable, expected: Iterable, message?: string | Error, equalityComparer?: IEqualityComparer): void; /** * Tests sequential equality between the actual and expected iterables. * * @param actual The actual value to evaluate. * @param expected The expected value. * @param equalityComparer Optional equality comparer to use to compare items in the iterables. */ notSequenceEqual(actual: Iterable, expected: Iterable, equalityComparer?: IEqualityComparer): void; /** * Awaits the asyncFn promise or, if asyncFn is a function, immediately calls the function and awaits the returned promise to complete. It will then check that the promise is rejected. * * @param asyncFn If asyncFn is a function and it throws an error synchronously, it will return a rejected Promise with that error. If the function does not return a promise, assert.rejects() will return a rejected Promise with an ERR_INVALID_RETURN_VALUE error. In both cases the error handler is skipped. * @param error Validate error message using RegExp, custom error validation using predicate, instanceof using constructor or the Error message string. * @param messageOrError Optional custom text or error to report in the case of failure. */ rejects(asyncFn: (() => Promise) | Promise, error?: Error | RegExp | ErrorValidatorPredicate | Constructor | string, messageOrError?: string | Error): Promise; /** * Awaits the asyncFn promise or, if asyncFn is a function, immediately calls the function and awaits the returned promise to complete. It will then check that the promise is not rejected. * * @param asyncFn If asyncFn is a function and it throws an error synchronously, it will return a rejected Promise with that error. If the function does not return a promise, assert.doesNotReject() will return a rejected Promise with an ERR_INVALID_RETURN_VALUE error. In both cases the error handler is skipped. * @param error Validate error message using RegExp, custom error validation using predicate, instanceof using constructor or the Error message string. * @param messageOrError Optional custom text or error to report in the case of failure. */ doesNotReject(asyncFn: (() => Promise) | Promise, error?: RegExp | ErrorValidatorPredicate, messageOrError?: string | Error): Promise; /** * Awaits the asyncFn promise or, if asyncFn is a function, immediately calls the function and awaits the returned promise to complete. It will then check that the promise is rejected. * * @param asyncFn If asyncFn is a function and it throws an error synchronously, it will return a rejected Promise with that error. If the function does not return a promise, assert.rejects() will return a rejected Promise with an ERR_INVALID_RETURN_VALUE error. In both cases the error handler is skipped. * @param error The error constructor to check for. * @param errorMessage The error.msg to check for. * @param message */ rejectsError(asyncFn: (() => Promise) | Promise, error: Constructor, errorMessage: string, message?: string): Promise; /** * Awaits the asyncFn promise or, if asyncFn is a function, immediately calls the function and awaits the returned promise to complete. It will then check that the promise is not rejected. * * @param asyncFn If asyncFn is a function and it throws an error synchronously, it will return a rejected Promise with that error. If the function does not return a promise, assert.doesNotReject() will return a rejected Promise with an ERR_INVALID_RETURN_VALUE error. In both cases the error handler is skipped. * @param error The error constructor to check for. * @param errorMessage The error.msg to check for. * @param message */ doesNotRejectError(asyncFn: (() => Promise) | Promise, error: Constructor, errorMessage: string, message?: string): Promise; /** * Expects the function fn to throw an error. * * @param fn The function to evaluate. * @param error Validate error message using RegExp, custom error validation using predicate, instanceof using constructor or the Error message string. * @param messageOrError Optional custom text or error to report in the case of failure. */ throws(fn: () => any, error?: RegExp | ErrorValidatorPredicate | ErrorValidatorMap | Constructor | string, messageOrError?: string | Error): void; /** * Asserts that the function fn does not throw an error. * * @param fn The function to evaluate. * @param error Validate error message using RegExp, custom error validation using predicate or instanceof using constructor. * @param messageOrError Optional custom text or error to report in the case of failure. */ doesNotThrow(fn: () => any, error?: RegExp | ErrorValidatorPredicate, messageOrError?: string | Error): void; /** * Expects the function fn to throw an error type. * * @param fn The function to evaluate. * @param error The Error type to check for. * @param errorMessage The error.msg to check for. * @param message Optional custom text to report in the case of failure. */ throwsError(fn: () => any, error: Constructor, errorMessage: string, message?: string): void; /** * Expects the function fn to not throw an error type. * * @param fn The function to evaluate. * @param error The Error type to check for. * @param errorMessage The error.msg to check for. * @param message Optional custom text to report in the case of failure. */ doesNotThrowError(fn: () => any, error: Constructor, errorMessage: string, message?: string): void; /** * Expect the actual value to be an instance of the expected object. * * @param actual The actual value to evaluate. * @param expected The expected value. */ instanceOf(actual: T, expected: Constructor): void; private getMessage; private getEqualityComparer; } export {};