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

    Interface IAssertInst

    Interface for assertion instance operations, this extends the core assertion instance and provides additional operations.

    This interface extends IAssertInstCore and IEqualOp<IAssertInst>. It provides various operations for performing assertions on instance.

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

    const inst: IAssertInst = {
    not: ...,
    deep: ...,
    own: ...,
    all: ...,
    any: ...,
    include: ...,
    includes: ...,
    contain: ...,
    contains: ...,
    strictly: ...,
    is: ...,
    ok: ...,
    throws: ...,
    toThrow: ...,
    toThrowError: ...,
    match: ...,
    hasProperty: ...,
    hasOwnProperty: ...
    };

    0.1.0

    interface IAssertInst {
        all: IAllOp<IAssertInst>;
        any: IAnyOp<IAssertInst>;
        contain: IIncludeOp<IAssertInst>;
        contains: IIncludeOp<IAssertInst>;
        deep: IDeepOp<IAssertInst>;
        eq: EqualFn<IAssertInst>;
        equal: EqualFn<IAssertInst>;
        equals: EqualFn<IAssertInst>;
        fail(msg?: MsgSource, details?: any): never;
        fail(
            actual: any,
            expected: any,
            failMsg?: MsgSource,
            operator?: string,
        ): never;
        fatal(msg: MsgSource, details?: any): never;
        has: IHasOp<IAssertInst>;
        hasOwnProperty(name: string, evalMsg?: MsgSource): IAssertInst;
        hasProperty(name: string, evalMsg?: MsgSource): IAssertInst;
        include: IIncludeOp<IAssertInst>;
        includes: IIncludeOp<IAssertInst>;
        is: IIsOp<IAssertInst>;
        match(regexp: RegExp, evalMsg?: MsgSource): IAssertInst;
        not: IAssertInst;
        ok(evalMsg?: MsgSource): IAssertInst;
        own: IOwnOp<IAssertInst>;
        strictly: IStrictlyOp<IAssertInst>;
        throws: ThrowFn;
        to: IToOp<IAssertInst>;
        toThrow: ThrowFn;
        toThrowError: ThrowFn;
    }

    Hierarchy (View Summary)

    Index

    Properties

    Provides operations for asserting that all conditions in a chain are met.

    This operation allows you to assert that all specified conditions are true for the target value. It is useful for combining multiple assertions into a single chain, ensuring that all conditions must pass.

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

    const obj = { a: 1, b: 2, c: 3 };

    assert(obj).all.keys('a', 'b', 'c'); // Passes
    assert(obj).all.keys('a', 'b', 'd'); // Fails

    Provides operations for asserting that any condition in a chain is met.

    This operation allows you to assert that at least one of the specified conditions is true for the target value. It is useful for combining multiple assertions into a single chain, ensuring that at least one condition must pass.

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

    const obj = { a: 1, b: 2, c: 3 };

    assert(obj).any.keys('a', 'x'); // Passes
    assert(obj).any.keys('x', 'y'); // Fails

    Provides operations for containment checks.

    This operation allows you to assert that the target value contains the specified value(s). It is useful for verifying that an array, string, or object contains certain elements or properties.

    include

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

    const arr = [1, 2, 3];
    const str = "hello darkness my old friend";
    const obj = { a: 1, b: 2, c: 3 };

    assert(arr).contain(2); // Passes
    assert(str).contain("darkness"); // Passes
    assert(obj).contain.all.keys('a', 'b'); // Passes
    assert(arr).contain(4); // Fails
    assert(str).contain("planet"); // Fails
    assert(obj).contain.all.keys('a', 'd'); // Fails

    Provides operations for containment checks.

    This operation allows you to assert that the target value contains the specified value(s). It is useful for verifying that an array, string, or object contains certain elements or properties.

    include

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

    const arr = [1, 2, 3];
    const str = "hello darkness my old friend";
    const obj = { a: 1, b: 2, c: 3 };

    assert(arr).contains(2); // Passes
    assert(str).contains("darkness"); // Passes
    assert(obj).contains.all.keys('a', 'b'); // Passes
    assert(arr).contains(4); // Fails
    assert(str).contains("planet"); // Fails
    assert(obj).contains.all.keys('a', 'd'); // Fails

    This operation provides access to operations that will deeplyallows you to assert that the target value deeply equals the expected value. It is useful for comparing objects, arrays, and other complex structures.

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

    assert({ a: 1, b: { c: 2 } }).deep.equal({ a: 1, b: { c: 2 } }); // Passes
    assert([1, [2, 3]]).deep.equal([1, [2, 3]]); // Passes
    assert({ a: 1, b: { c: 2 } }).deep.equal({ a: 1, b: { c: 3 } }); // Fails

    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.

    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

    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.

    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

    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.

    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

    Provides operations for checking whether the target value has a specific property.

    This operation allows you to assert that the target value has the specified property. It is useful for verifying that an object has a certain property.

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

    const obj = { a: 1, b: 2 };

    assert(obj).has.property('a'); // Passes
    assert(obj).has.property('c'); // Fail

    Provides operations for inclusion checks.

    This operation allows you to assert that the target value includes the specified value(s). It is useful for verifying that an array, string, or object contains certain elements or properties.

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

    const arr = [1, 2, 3];
    const str = "hello darkness my old friend";
    const obj = { a: 1, b: 2, c: 3 };

    assert(arr).include(2); // Passes
    assert(str).include("darkness"); // Passes
    assert(obj).include.all.keys('a', 'b'); // Passes
    assert(arr).include(4); // Fails
    assert(str).include("planet"); // Fails
    assert(obj).include.all.keys('a', 'd'); // Fails

    Provides operations for inclusion checks.

    This operation allows you to assert that the target value includes the specified value(s). It is useful for verifying that an array, string, or object contains certain elements or properties.

    include

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

    const arr = [1, 2, 3];
    const str = "hello darkness my old friend";
    const obj = { a: 1, b: 2, c: 3 };

    assert(arr).includes(2); // Passes
    assert(str).includes("darkness"); // Passes
    assert(obj).includes.all.keys('a', 'b'); // Passes
    assert(arr).includes(4); // Fails
    assert(str).includes("planet"); // Fails
    assert(obj).includes.all.keys('a', 'd'); // Fails

    Provides operations for type and equality checks.

    This operation allows you to assert that the target value is of the specified type. It is useful for verifying the type of a value, such as a number, string, or object.

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

    assert(1).is.a.number(); // Passes
    assert("hello").is.a.string(); // Passes
    assert({ a: 1 }).is.an.object(); // Passes
    assert(1).is.string(); // Fails
    assert("hello").is.number(); // Fails
    assert({ a: 1 }).is.array(); // Fails

    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

    Provides operations for ownership checks.

    This operation allows you to assert that the target object has its own property with the specified name. It is useful for verifying that an object has a property directly on itself, rather than inheriting it from its prototype chain.

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

    const obj = { a: 1 };
    const proto = { b: 2 };
    Object.setPrototypeOf(obj, proto);

    assert(obj).own.property('a'); // Passes
    assert(obj).own.property('b'); // Fails

    Provides operations for strict equality checks.

    This operation allows you to assert that the target value is strictly equal to the expected value. It is useful for comparing values without any type coercion.

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

    assert(1).strictly.equal(1); // Passes
    assert(1).strictly.equal("1"); // Fails
    throws: ThrowFn

    Asserts that the value is a function that when executed will throw an error.

    Optional. The error to match.

    Optional. The message to match.

    Optional. The message to display if the assertion fails.

    The result of the operation.

    AssertionFailure - If the function does not throw an error.

    AssertionError - If the error thrown does not match the expected error.

    AssertionError - If the error message does not match the expected message.

    Provides syntatic operations for accessing whether the target is of a specific type, has a specific property, or is strictly equal to a specific value.

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

    assert(1).is.a.number(); // Passes
    assert(1).to.be.a.number(); // Passes

    assert(1).is.number(); // Passes
    assert(1).to.be.number(); // Passes
    toThrow: ThrowFn
    toThrowError: ThrowFn

    Methods