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

    Interface IIsOp<R>

    Represents an interface for operations on an assertion scope confirming the type of a value.

    interface IIsOp<R> {
        a: IIsOp<R>;
        above: NumberFn<R>;
        an: IIsOp<R>;
        approximately: CloseToFn<R>;
        array: AssertFn<R>;
        below: NumberFn<R>;
        boolean: AssertFn<R>;
        closeTo: CloseToFn<R>;
        empty: AssertFn<R>;
        eq: EqualFn<R>;
        equal: EqualFn<R>;
        equals: EqualFn<R>;
        error: ErrorLikeFn<R>;
        extensible: AssertFn<R>;
        false: AssertFn<R>;
        finite: AssertFn<R>;
        frozen: AssertFn<R>;
        function: AssertFn<R>;
        greaterThan: NumberFn<R>;
        greaterThanOrEqual: NumberFn<R>;
        gt: NumberFn<R>;
        gte: NumberFn<R>;
        instanceof: InstanceOfFn<R>;
        instanceOf: InstanceOfFn<R>;
        iterable: AssertFn<R>;
        least: NumberFn<R>;
        lessThan: NumberFn<R>;
        lessThanOrEqual: NumberFn<R>;
        lt: NumberFn<R>;
        lte: NumberFn<R>;
        most: NumberFn<R>;
        nan: AssertFn<R>;
        not: IIsOp;
        null: AssertFn<R>;
        number: AssertFn<R>;
        object: AssertFn<R>;
        ok: AssertFn<R>;
        oneOf: OneOfFn<R>;
        plainObject: AssertFn<R>;
        sealed: AssertFn<R>;
        strictly: IStrictlyOp<R>;
        string: AssertFn<R>;
        true: AssertFn<R>;
        truthy: AssertFn<R>;
        typeOf(type: string, evalMsg?: MsgSource): R;
        undefined: AssertFn<R>;
        within: WithinFn<R>;
    }

    Type Parameters

    • R

      The type of the result of the operation.

    Hierarchy (View Summary)

    Index

    Properties

    a: IIsOp<R>

    A decorative / alias operation which returns the current instance, useful for chaining operations to provide a more descriptive description of the operations being performed within your tests.

    • The current instance.
    expect(1).is.a.number();
    expect(1).to.be.a.number();

    // This is equivalent to not using this decorator operation
    expect(1).is.number()
    expect(1).to.be.number();
    above: NumberFn<R>
    an: IIsOp<R>

    A decorative / alias operation which returns the current instance, useful for chaining operations to provide a more descriptive description of the operations being performed within your tests.

    • The current instance.
    expect(1).is.an.object();
    expect(1).to.be.an.array();

    // This is equivalent to not using this decorator operation
    expect(1).is.object()
    expect(1).to.be.array();
    approximately: CloseToFn<R>

    Alias for closeTo. Asserts that the target is a number approximately equal to the given number within a specified delta.

    The expected value to compare against.

    The maximum allowed difference between actual and expected. Note: A negative delta will never result in a passing assertion since the absolute difference is always non-negative.

    The message to evaluate if the assertion fails.

    The result of the operation.

    0.1.5

    import { assert } from "@nevware21/tripwire";

    expect(1.5).is.approximately(1.0, 0.5); // Passes - difference is 0.5
    expect(10).to.be.approximately(20, 20); // Passes - difference is 10
    array: AssertFn<R>

    Asserts that the value is an array.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    below: NumberFn<R>
    boolean: AssertFn<R>

    Asserts that the value is a boolean.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    closeTo: CloseToFn<R>

    Asserts that the target is a number close to the given number within a specified delta. This is useful for floating-point comparisons where exact equality is not guaranteed.

    The expected value to compare against.

    The maximum allowed difference between actual and expected. Note: A negative delta will never result in a passing assertion since the absolute difference is always non-negative.

    The message to evaluate if the assertion fails.

    The result of the operation.

    0.1.5

    import { assert } from "@nevware21/tripwire";

    expect(1.5).is.closeTo(1.0, 0.5); // Passes - difference is 0.5
    expect(10).is.closeTo(20, 20); // Passes - difference is 10
    expect(-10).is.closeTo(20, 30); // Passes - difference is 30
    expect(2).is.closeTo(1.0, 0.5); // Fails - difference is 1.0
    empty: AssertFn<R>

    Asserts that the value is empty.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    eq: EqualFn<R>

    Performs an equality check between the actual and expected values, throwing an AssertionFailure with the given message when the actual value is not equal to the expected value. The default equality check is a loose (==) equality check, to perform a strict equality check (===), use the IStrictlyOp.equal (strictly.equal) operations and when comparing complex objects, use the deep equality operations provided by the IDeepOp.equal (deep.equal) operations or (deep.strictly.equal) for deep strict equality checks. IStrictlyOp.eq (strictly.eq) operations.

    The type of the expected value.

    The expected value.

    The message to display if the values are strictly equal.

    An AssertionFailure if the expected and actual values are strictly equal.

    assert.eq(1, 1); // Passes
    assert.eq("a", "a"); // Passes
    assert.eq(true, true); // Passes
    assert.eq(false, false); // Passes
    assert.eq(null, null); // Passes
    assert.eq(undefined, undefined); // Passes
    assert.eq(0, 0); // Passes
    assert.eq(-0, -0); // Passes
    assert.eq(+0, +0); // Passes
    assert.eq(0n, 0n); // Passes
    assert.eq("", ""); // Passes
    assert.eq(Symbol(), Symbol()); // Passes
    assert.eq([], []); // Throws AssertionError
    assert.eq([1, 2], [1, 2]); // Throws AssertionError
    equal: EqualFn<R>

    Performs an equality check between the actual and expected values, throwing an AssertionFailure with the given message when the actual value is not equal to the expected value. The default equality check is a loose (==) equality check, to perform a strict equality check (===), use the IStrictlyOp.equal (strictly.equal) operations and when comparing complex objects, use the deep equality operations provided by the IDeepOp.equal (deep.equal) operations or (deep.strictly.equal) for deep strict equality checks.

    The type of the expected value.

    The expected value.

    The message to display if the values are not strictly equal.

    An AssertionFailure if the expected and actual values are not strictly equal.

    assert.equal(1, 1); // Passes
    assert.equal("a", "a"); // Passes
    assert.equal(true, true); // Passes
    assert.equal(false, false); // Passes
    assert.equal(null, null); // Passes
    assert.equal(undefined, undefined); // Passes
    assert.equal(0, 0); // Passes
    assert.equal(-0, -0); // Passes
    assert.equal(+0, +0); // Passes
    assert.equal(0n, 0n); // Passes
    assert.equal("", ""); // Passes
    assert.equal(Symbol(), Symbol()); // Passes
    assert.equal([], []); // Throws AssertionError
    assert.equal([1, 2], [1, 2]); // Throws AssertionError
    equals: EqualFn<R>

    Performs an equality check between the actual and expected values, throwing an AssertionFailure with the given message when the actual value is not equal to the expected value. The default equality check is a loose (==) equality check, to perform a strict equality check (===), use the IStrictlyOp.equal (strictly.equal) operations and when comparing complex objects, use the deep equality operations provided by the IDeepOp.equal (deep.equal) operations or (deep.strictly.equal) for deep strict equality checks.

    The type of the expected value.

    The expected value.

    The message to display if the values are strictly equal.

    An AssertionFailure if the expected and actual values are strictly equal.

    assert.equals(1, 1); // Passes
    assert.equals("a", "a"); // Passes
    assert.equals(true, true); // Passes
    assert.equals(false, false); // Passes
    assert.equals(null, null); // Passes
    assert.equals(undefined, undefined); // Passes
    assert.equals(0, 0); // Passes
    assert.equals(-0, -0); // Passes
    assert.equals(+0, +0); // Passes
    assert.equals(0n, 0n); // Passes
    assert.equals("", ""); // Passes
    assert.equals(Symbol(), Symbol()); // Passes
    assert.equals([], []); // Throws AssertionError
    assert.equals([1, 2], [1, 2]); // Throws AssertionError
    error: ErrorLikeFn<R>

    Asserts that the value is an error or matches the provided error constructor.

    The error or error constructor to match.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    extensible: AssertFn<R>

    Asserts that the value is extensible.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    false: AssertFn<R>

    Asserts that the value is false.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    finite: AssertFn<R>

    Asserts that the value is a finite number (not NaN, not Infinity, not -Infinity).

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    0.1.5

    frozen: AssertFn<R>

    Asserts that the value is frozen.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    function: AssertFn<R>

    Asserts that the value is a function.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    greaterThan: NumberFn<R>
    greaterThanOrEqual: NumberFn<R>
    gt: NumberFn<R>
    gte: NumberFn<R>
    instanceof: InstanceOfFn<R>

    Asserts that the value is an instance of the specified constructor.

    The constructor to check against (e.g., Array, Date, Error, custom class).

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    0.1.5

    instanceOf: InstanceOfFn<R>

    Asserts that the value is an instance of the specified constructor.

    The constructor to check against (e.g., Array, Date, Error, custom class).

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    0.1.5

    iterable: AssertFn<R>

    Asserts that the value is iterable.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    least: NumberFn<R>
    lessThan: NumberFn<R>
    lessThanOrEqual: NumberFn<R>
    lt: NumberFn<R>
    lte: NumberFn<R>
    most: NumberFn<R>
    nan: AssertFn<R>

    Asserts that the value is NaN.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    0.1.5

    not: IIsOp

    Negates any performed evaluations that are performed in the assertion chain.

    This operation applies a stateful change to the evaluation chain, meaning that subsequent operations that would normally fail will pass without the need for them to "implement" any knowledge about the not operation. You may call not multiple times to negate the negation.

    import { assert } from "@nevware21/tripwire";

    expect(true).not.ok(); // Fails
    expect(false).not.ok(); // Passes
    expect(true).not.not.ok(); // Passes
    expect(false).not.not.ok(); // Fails
    null: AssertFn<R>

    Asserts that the value is null.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    number: AssertFn<R>

    Asserts that the value is a number.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    object: AssertFn<R>

    Asserts that the value is an object.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    ok: AssertFn<R>

    Asserts that the value is truthy.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    oneOf: OneOfFn<R>

    Asserts that the target value is a member of the given list. Uses strict equality (===) to check if the value is in the list.

    The array of possible values to check against.

    The message to evaluate if the assertion fails.

    The result of the operation.

    0.1.5

    import { expect } from "@nevware21/tripwire";

    expect(1).is.oneOf([1, 2, 3]); // Passes
    expect("a").is.oneOf(["a", "b", "c"]); // Passes
    expect(5).to.not.be.oneOf([1, 2, 3]); // Passes
    expect("x").is.not.oneOf(["a", "b", "c"]); // Passes
    plainObject: AssertFn<R>

    Asserts that the value is a plain object.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    sealed: AssertFn<R>

    Asserts that the value is sealed.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    strictly: IStrictlyOp<R>

    Provides access to operations to confirm that the value strictly matches the type based on the used assertion operator.

    The custom message to display on evaluation.

    An object that provides operations to assert the value is strictly of the specified operation.

    string: AssertFn<R>

    Asserts that the value is a string.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    true: AssertFn<R>

    Asserts that the value is true.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    truthy: AssertFn<R>

    Asserts that the value is truthy.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    undefined: AssertFn<R>

    Asserts that the value is undefined.

    The custom message to display on evaluation.

    The current IAssertScope.that object.

    An AssertionFailure if the assertion fails.

    within: WithinFn<R>

    Methods

    • Asserts that the value's type matches the expected type string. Uses the JavaScript typeof operator for type comparison.

      Valid type strings include:

      • "string"
      • "number"
      • "bigint"
      • "boolean"
      • "symbol"
      • "undefined"
      • "object" (includes null, arrays, and objects)
      • "null"
      • "array"
      • "function" (includes async, generator, and async generator functions)
      • "asyncfunction"
      • "generatorfunction"
      • "asyncgeneratorfunction"

      Parameters

      • type: string

        The expected type string (e.g., "string", "number", "function")

      • OptionalevalMsg: MsgSource

        The custom message to display on evaluation.

      Returns R

      The current IAssertScope.that object.

      An AssertionFailure if the assertion fails.

      0.1.5

      expect("hello").is.typeof("string");
      expect(123).to.be.typeof("number");
      expect({}).is.typeof("object");
      expect(() => {}).to.be.typeof("function");