• Test function. Checks that a synchronous function throws an error on execution. It returns a serialized thrown error. Allows easier inspection of the thrown error.

    The returned object is serialized because jest detects Error classes and can decide to compare only message property, ignoring all others. Recommended to not compare returned type agains an object of Error type.

    Type Parameters

    • TErrorType = any

    Parameters

    • fn: (() => unknown)
        • (): unknown
        • Returns unknown

    Returns TErrorType

    Example

     const error = expectFailure<MosaicError>(() => syncFunction(param));

    expect(error.message).toBe('Some error message');
    expect(error.code).toBe('SOME_CODE');

    For async functions use rejectionOf

Generated using TypeDoc