Function assertThrows

Asserts that the given callback or promise throws and that what it throws matches, if provided, the provided constructor or message string.

  • Asserts that the given callback or promise throws and that what it throws matches, if provided, the provided constructor or message string.

    Parameters

    • callback: Promise<any>

      The callback or promise to check for throwing.

    • Optionalmatching: PartialAndNullable<{
          matchConstructor: ErrorConstructor | (new (...args: any[]) => Error);
          matchMessage: string | RegExp;
      }>

      Optional matching options.

    • OptionalfailureMessage: string

      Message to include in the error if the provided callback or promise does not throw.

    Returns Promise<void>

  • Asserts that the given callback or promise throws and that what it throws matches, if provided, the provided constructor or message string.

    Parameters

    • callback: ((...args: []) => Promise<any>)

      The callback or promise to check for throwing.

        • (...args): Promise<any>
        • Parameters

          • Rest...args: []

          Returns Promise<any>

    • Optionalmatching: PartialAndNullable<{
          matchConstructor: ErrorConstructor | (new (...args: any[]) => Error);
          matchMessage: string | RegExp;
      }>

      Optional matching options.

    • OptionalfailureMessage: string

      Message to include in the error if the provided callback or promise does not throw.

    Returns Promise<void>

  • Asserts that the given callback or promise throws and that what it throws matches, if provided, the provided constructor or message string.

    Parameters

    • callback: ((...args: []) => any)

      The callback or promise to check for throwing.

        • (...args): any
        • Parameters

          • Rest...args: []

          Returns any

    • Optionalmatching: PartialAndNullable<{
          matchConstructor: ErrorConstructor | (new (...args: any[]) => Error);
          matchMessage: string | RegExp;
      }>

      Optional matching options.

    • OptionalfailureMessage: string

      Message to include in the error if the provided callback or promise does not throw.

    Returns void

  • Asserts that the given callback or promise throws and that what it throws matches, if provided, the provided constructor or message string.

    Parameters

    • callback: ((...args: []) => any)

      The callback or promise to check for throwing.

        • (...args): any
        • Parameters

          • Rest...args: []

          Returns any

    • Optionalmatching: PartialAndNullable<{
          matchConstructor: ErrorConstructor | (new (...args: any[]) => Error);
          matchMessage: string | RegExp;
      }>

      Optional matching options.

    • OptionalfailureMessage: string

      Message to include in the error if the provided callback or promise does not throw.

    Returns MaybePromise<void>

  • Asserts that the given callback or promise throws and that what it throws matches, if provided, the provided constructor or message string.

    Parameters

    • callbackOrPromise: CallbackOrPromise

      The callback or promise to check for throwing.

    • Optionalmatching: PartialAndNullable<{
          matchConstructor: ErrorConstructor | (new (...args: any[]) => Error);
          matchMessage: string | RegExp;
      }>

      Optional matching options.

    • OptionalfailureMessage: string

      Message to include in the error if the provided callback or promise does not throw.

    Returns MaybePromise<void>