Interface Assertions<T, N>

Assertions

interface Assertions<T, N> {
    not: N;
    toBe(expected: T): void;
    toBeFalsy(): void;
    toBeOfType<U>(
        ...params: <V>() => V extends T ? 1 : 2 extends <V>() => V extends U
            ? 1
            : 2
            ? []
            : ["ERROR: The types are not the same"],
    ): void;
    toBeTruthy(): void;
    toEqual(expected: Exclude<T, Function | Promise<unknown>>): void;
    toReject(expectedError?: string | RegExp | Error): Promise<void>;
    toResolve(expected?: Awaited<T>): Promise<void>;
    toThrow(expectedError?: string | RegExp | Error): void;
}

Type Parameters

  • T
  • N

Properties

not: N

Negate the meaning of the assertion

Methods

  • Assert that the actual and expected values are not only equal but identical (i.e. the same instance)

    Parameters

    • expected: T

      The expected value

    Returns void

    If the actual and expected values are not identical (even if they are equal)

  • Assert that the actual value is falsy

    Returns void

    If the actual value is truthy

  • Assert that the actual value is of the specified type

    Type Parameters

    • U

    Parameters

    • ...params: <V>() => V extends T ? 1 : 2 extends <V>() => V extends U ? 1 : 2
          ? []
          : ["ERROR: The types are not the same"]

    Returns void

  • Assert that the actual value is truthy

    Returns void

    If the actual value is falsy

  • Assert that the actual and expected values are equal (even if they are different instances)

    Parameters

    • expected: Exclude<T, Function | Promise<unknown>>

      The expected value

    Returns void

    If the actual and expected values are not equal

  • Assert that the promise rejects (with the expected error, if given)

    Parameters

    • OptionalexpectedError: string | RegExp | Error

      The expected error or error message

    Returns Promise<void>

    If the promise resolves or if it rejects with an error other than the expected one (if given)

  • Assert that the promise resolves (to the expected value, if given)

    Parameters

    • Optionalexpected: Awaited<T>

      The expected resolved value

    Returns Promise<void>

    If the promise rejects or if it resolves to a value other than the expected one (if given)

  • Assert that the code block throws an error matching the expected one (if given)

    Parameters

    • OptionalexpectedError: string | RegExp | Error

      The expected error or error message

    Returns void

    If the code block does not raise an error or if it raises an error other than the expected one (if given)