@nevware21/tripwire - v0.1.2
    Preparing search index...

    Interface IAssertScope

    The IAssertScope interface provides the main entry point for the assertion chain execution, it provides the main functions for creating new IAssertInst instances and IAssertScope instances as well as the main functions for executing the assertion chain and evaluating the final result.

    The IAssertScope is used to create new IAssertInst instances with the given value and optional overrides, it also provides the main functions for executing the assertion chain and evaluating the final result.

    0.1.0

    interface IAssertScope {
        context: IScopeContext;
        createOperation<T>(funcs: AssertScopeFuncDefs<T>, obj?: any): T;
        exec<F extends IScopeFn, R = ReturnType<F>>(
            fn: F,
            args: Parameters<F>,
            funcName?: string,
        ): R;
        fail(failMsg: MsgSource, details?: any): never;
        fail(
            actual: any,
            expected: any,
            failMsg?: MsgSource,
            operator?: string,
        ): never;
        fatal(msg: MsgSource, details?: any): never;
        newEmptyInst(): any;
        newInst<V>(value?: V, overrides?: IScopeContextOverrides): any;
        newScope<V>(value?: V): IAssertScope;
        that: any;
        updateCtx<T>(value: T, overrides?: IScopeContextOverrides): this;
    }
    Index

    Properties

    context: IScopeContext

    Holds the current context of the assertion chain execution, this is passed to all scope functions and is used to evaluate the final result of the assertion chain as well as resolving the final message withe the values of the execution chain.

    that: any

    Keeps track of the current this context for the assertions, this starts out as the initial IAssertInst object but is changed during the evaluation of the operations, which allows operations to be chained together even when the subsequent operations return different this objects that do not inherit from or extend the initial IAssertInst object.

    Methods

    • Creates a new operation by adding the functions / properties as defined by the IAssertScopeFuncDef type to the obj, when no obj is passed a new empty IAssertInstCore instance is created, decorated and returned. The returned object is "generally" returned from the IScopeFn functions and is used to chain the next operation.

      Type Parameters

      • T

      Parameters

      • funcs: AssertScopeFuncDefs<T>

        The functions / properties to add to the object.

      • Optionalobj: any

        The optional object to decorate with the defined operations, if no obj is provided then an empty IAssertInstCore will be used.

      Returns T

    • Executes the given function within the scope this of the current IAssertScope passing the provided arguments, the result of the function will be returned.

      Type Parameters

      Parameters

      • fn: F

        The function to execute.

      • args: Parameters<F>

        The arguments to pass to the function.

      • OptionalfuncName: string

        The optional name of the function to execute.

      Returns R

      The result of the function.

    • Throws an AssertionFailure exception with the given message and optional details which are obtained via the getDetails function.

      Parameters

      • failMsg: MsgSource

        The message to display.

      • Optionaldetails: any

        The details (props) to include in the error

      Returns never

      AssertionFailure always

    • Generic failure that throws an AssertionFailure exception with the given message and optional details which are obtained via the getDetails function.

      Parameters

      • actual: any

        The actual value that was expected

      • expected: any

        The expected value that was not found

      • OptionalfailMsg: MsgSource

        The message to display.

      • Optionaloperator: string

        The optional operator used in the comparison

      Returns never

      AssertionFailure always

    • Creates a new empty IAssertInstCore assert instance that can be extended or decorated with instance functions for usage via operations. The default implementation returns an object that does not inherit or have access to the IAssertInst functions.

      Returns any

    • Creates a new "standard" assert instance with the given value and optional override functions, if no arguments are provided then the current scope context value is used, however, if undefined or null is provided then the value is set to the provided value.

      Type Parameters

      • V

      Parameters

      • Optionalvalue: V

        The new value of the context, this is the actual value of the assertion.

      • Optionaloverrides: IScopeContextOverrides

        The optional overrides for the context

      Returns any

    • Creates a new Scope instance, it will also create child instances of the current context so that any changes applied on this new scope will not alter the current scope.

      Type Parameters

      • V

      Parameters

      • Optionalvalue: V

        The new value of the context, this is the actual value of the assertion.

      Returns IAssertScope

      The new scope instance.

    • Updates the current context with the given value and optional overrides, this is used to update the current context with the new value and overrides. It avoids the need to create a new IAssertScope or IAssertInst instance for each operation and allows the scope to be updated in place, so all existing scope functions of the current instance can be chained together.

      Type Parameters

      • T

      Parameters

      • value: T

        The value to update the context with.

      • Optionaloverrides: IScopeContextOverrides

        The optional overrides for the context

      Returns this

      The current IAssertScope instance.