@kayahr/assert
    Preparing search index...

    Function assertThrow

    Asserts that given function (synchronous or asynchronous) does throw an exception. When function is asynchronous then assertThrow returns a Promise which must be awaited in order to complete the assertion.

    Examples:

    assertThrow(() => someSyncFunc());
    assertThrow(() => someSyncFunc(), new SomeError("Message");
    await assertThrow(() => someAsyncFunc());
    await assertThrow(() => someAsyncFunc(), new SomeError("Message");
    • Asserts that given asynchronous function does reject the returned promise.

      Parameters

      • fn: () => Promise<unknown>

        The function to call.

      • Optionalerror: unknown

        Optional error to compare thrown exception to. If specified then assertion fails when function does not throw an exception equal to this one. If not specified then assertion fails when function does not throw anything.

      • Optionalreason: string

        Optional reason added to exception message when assertion fails.

      Returns Promise<void>

      Promise which must be awaited in order to complete assertion.

      AssertionError when function throws exception not matching the given one (or does not throw anything when no error specified).

    • Parameters

      • fn: () => unknown

        The function to call.

      • Optionalerror: unknown

        Optional error to compare thrown exception to. If specified then assertion fails when function does not throw an exception equal to this one. If not specified then assertion fails when function does not throw anything.

      • Optionalreason: string

        Optional reason added to exception message when assertion fails.

      Returns void

      AssertionError when function throws exception not matching the given one (or does not throw anything when no error specified).