typefinity
    Preparing search index...

    Class Assertions<T, N>

    Assertions

    Type Parameters

    • T
    • N
    Index

    Constructors

    • Initialization

      Type Parameters

      • T
      • N

      Parameters

      • actual: T

        The actual value to be inspected

      • not: N

        The negate the meaning of the assertion

      Returns Assertions<T, N>

    Properties

    not: N

    Methods

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

      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 an instance of the specified class

      Type Parameters

      • U

      Parameters

      • expected: new (...args: any[]) => T extends U ? U : T

        The expected class

      Returns void

      If the actual value is not an instance of the expected class

    • Assert that the actual value is of the specified type. This is a compile-time check:

      expect(1 as number | string).toBeOfType<number|string>() // ok
      expect(1 as number | string).toBeOfType<number>() // does not compile

      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"]

        Accepts no parameters when both types match

      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 actual string matches a regular expression

      Parameters

      • expected: RegExp

        The expected regular expression

      Returns void

      If the actual string does not match the regular expression (or if the actual value is not a string)

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

      Parameters

      • Optionalexpected: 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 inspect the resolved value, pass the promise to expect (rather than using toResolve).

      await expect(await promise).toBe(expected);
      

      Returns Promise<void>

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

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

      Parameters

      • Optionalexpected: string | RegExp | Error

        The expected error or error message

      Returns void

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