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

    Interface IChangeResultOp

    Result type for change assertions that allows chaining .by() to verify the magnitude of change. Returned by change/increase/decrease assertions to enable fluent chaining syntax.

    0.1.5

    expect(fn).to.change(obj, 'val').by(5);      // Verify it changed by exactly 5
    expect(fn).to.increase(obj, 'val').by(10); // Verify it increased by exactly 10
    expect(fn).to.decrease(obj, 'val').by(3); // Verify it decreased by exactly 3
    expect(fn).to.change(obj, 'val').not.by(5); // Verify it didn't change by 5
    interface IChangeResultOp {
        all: IAllOp<IChangeResultOp>;
        any: IAnyOp<IChangeResultOp>;
        by(delta: number, evalMsg?: MsgSource): IAssertInst;
        change: ChangeFn;
        changeBy: ChangeByFn;
        changes: ChangeFn;
        changesButNotBy: ChangeByFn;
        changesBy: ChangeByFn;
        contain: IIncludeOp<IChangeResultOp>;
        contains: IIncludeOp<IChangeResultOp>;
        decrease: ChangeFn;
        decreaseBy: ChangeByFn;
        decreases: ChangeFn;
        decreasesButNotBy: ChangeByFn;
        decreasesBy: ChangeByFn;
        deep: IDeepOp<IChangeResultOp>;
        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<IChangeResultOp>;
        hasOwnProperty(name: string, evalMsg?: MsgSource): IAssertInst;
        hasProperty(name: string, evalMsg?: MsgSource): IAssertInst;
        include: IIncludeOp<IChangeResultOp>;
        includes: IIncludeOp<IChangeResultOp>;
        increase: ChangeFn;
        increaseBy: ChangeByFn;
        increases: ChangeFn;
        increasesButNotBy: ChangeByFn;
        increasesBy: ChangeByFn;
        is: IIsOp<IChangeResultOp>;
        match(regexp: RegExp, evalMsg?: MsgSource): IAssertInst;
        not: IChangeResultOp;
        ok(evalMsg?: MsgSource): IAssertInst;
        own: IOwnOp<IChangeResultOp>;
        strictly: IStrictlyOp<IChangeResultOp>;
        throws: ThrowFn;
        to: IToOp<IChangeResultOp>;
        toThrow: ThrowFn;
        toThrowError: ThrowFn;
        value: IAssertInst;
    }

    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
    change: ChangeFn

    Asserts that executing the target function changes the monitored value. Can monitor either a getter function's return value or an object property.

    0.1.5

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

    // With getter function
    let value = 10;
    const getValue = () => value;
    const addTwo = () => { value += 2; };
    expect(addTwo).to.change(getValue);
    expect(addTwo).to.change(getValue).by(2);

    // With object property
    const obj = { val: 10 };
    const increment = () => { obj.val++; };
    expect(increment).to.change(obj, 'val');
    expect(increment).to.change(obj, 'val').by(1);
    changeBy: ChangeByFn

    Asserts that executing the target function changes the monitored value by a specific delta. This is a direct method that doesn't require chaining with .by(). Important: The sign of the delta is ignored - only the absolute value is compared.

    0.1.5

    let value = 10;
    const getValue = () => value;
    const addFive = () => { value += 5; };
    const subtractFive = () => { value -= 5; };

    expect(addFive).to.changeBy(getValue, 5); // Passes - changed by +5
    expect(addFive).to.changeBy(getValue, -5); // Also passes - absolute value is 5
    expect(subtractFive).to.changeBy(getValue, 5); // Passes - absolute value is 5
    changes: ChangeFn

    Alias for change.

    0.1.5

    changesButNotBy: ChangeByFn

    Asserts that the value DOES change but NOT by the specified delta after executing the target function. The value MUST change (cannot remain the same), but the change amount must not equal the specified delta. This differs from notChangesBy which allows the value to remain unchanged.

    0.1.5

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

    let value = 0;
    const getValue = () => value;
    const addTwo = () => { value += 2; };
    const noOp = () => {};
    expect(addTwo).to.changesButNotBy(getValue, 5); // Passes - changed by 2, not by 5
    expect(addTwo).to.changesButNotBy(getValue, 2); // Fails - changed by exactly 2
    expect(noOp).to.changesButNotBy(getValue, 5); // Fails - no change occurred
    changesBy: ChangeByFn

    Alias for changeBy. The sign of the delta is ignored - only the absolute value is compared.

    0.1.5

    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 welcome back again";
    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 welcome back again";
    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
    decrease: ChangeFn

    Asserts that executing the target function decreases the monitored numeric value. Can monitor either a getter function's return value or an object property. When using .by(delta), the delta value should be a positive number as a decrease is expected.

    0.1.5

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

    // With getter function
    let count = 10;
    const getCount = () => count;
    const decrement = () => { count--; };
    expect(decrement).to.decrease(getCount);
    expect(decrement).to.decrease(getCount).by(1); // delta of 1 (positive) for a decrease

    // With object property
    const obj = { count: 10 };
    const subtractThree = () => { obj.count -= 3; };
    expect(subtractThree).to.decrease(obj, 'count');
    expect(subtractThree).to.decrease(obj, 'count').by(3); // delta of 3 (positive) for a decrease
    decreaseBy: ChangeByFn

    Asserts that executing the target function decreases the monitored value by a specific delta. This is a direct method that doesn't require chaining with .by(). Note: The delta should be specified as a positive value representing the magnitude of the decrease. For example, if a value goes from 10 to 7, use delta of 3, not -3.

    0.1.5

    let count = 10;
    const getCount = () => count;
    const subtractThree = () => { count -= 3; };
    expect(subtractThree).to.decreaseBy(getCount, 3); // Passes - use positive 3, not -3
    decreases: ChangeFn

    Alias for decrease.

    0.1.5

    decreasesButNotBy: ChangeByFn

    Asserts that the value DOES decrease but NOT by the specified delta after executing the target function. The value MUST decrease (must go down), but the decrease amount must not equal the specified delta. The delta value should be a positive number as a decrease is expected.

    0.1.5

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

    let count = 10;
    const getCount = () => count;
    const subtractTwo = () => { count -= 2; };
    expect(subtractTwo).to.decreasesButNotBy(getCount, 5); // Passes - decreased by 2, not by 5
    expect(subtractTwo).to.decreasesButNotBy(getCount, 2); // Fails - decreased by exactly 2
    decreasesBy: ChangeByFn

    Alias for decreaseBy.

    0.1.5

    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.

    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

    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

    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

    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 welcome back again";
    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.

    0.1.2

    include

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

    const arr = [1, 2, 3];
    const str = "hello darkness welcome back again";
    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
    increase: ChangeFn

    Asserts that executing the target function increases the monitored numeric value. Can monitor either a getter function's return value or an object property.

    0.1.5

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

    // With getter function
    let count = 0;
    const getCount = () => count;
    const increment = () => { count++; };
    expect(increment).to.increase(getCount);
    expect(increment).to.increase(getCount).by(1);

    // With object property
    const obj = { count: 5 };
    const addFive = () => { obj.count += 5; };
    expect(addFive).to.increase(obj, 'count');
    expect(addFive).to.increase(obj, 'count').by(5);
    increaseBy: ChangeByFn

    Asserts that executing the target function increases the monitored value by a specific delta. This is a direct method that doesn't require chaining with .by(). The delta value should be a positive number representing the expected increase.

    0.1.5

    let count = 5;
    const getCount = () => count;
    const addTen = () => { count += 10; };
    expect(addTen).to.increaseBy(getCount, 10); // Passes - increased by exactly 10
    increases: ChangeFn

    Alias for increase.

    0.1.5

    increasesButNotBy: ChangeByFn

    Asserts that the value DOES increase but NOT by the specified delta after executing the target function. The value MUST increase (must go up), but the increase amount must not equal the specified delta.

    0.1.5

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

    let count = 5;
    const getCount = () => count;
    const addTwo = () => { count += 2; };
    expect(addTwo).to.increasesButNotBy(getCount, 5); // Passes - increased by 2, not by 5
    expect(addTwo).to.increasesButNotBy(getCount, 2); // Fails - increased by exactly 2
    increasesBy: ChangeByFn

    Alias for increaseBy.

    0.1.5

    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 in the change assertion chain. When used after change/increase/decrease, the returned value still supports .by() to allow patterns like expect().to.change().not.by(delta)

    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.

    An AssertionFailure if the function does not throw an error.

    An AssertionError if the error thrown does not match the expected error.

    An 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

    A new IAssertInst with the resulting value from the change assertion. If monitoring a property, this will be the new value of that property. If monitoring a function, this will be the new return value of that function.

    expect(fn).to.change(obj, 'val').value.equals(15);
    

    Methods

    • Asserts that the change amount (delta) matches the expected delta.

      Parameters

      • delta: number

        The expected change amount

      • OptionalevalMsg: MsgSource

        Optional message to display if the assertion fails

      Returns IAssertInst

      The assertion result

      expect(fn).to.change(obj, 'val').by(5);
      expect(fn).to.increase(obj, 'val').by(10);
      expect(fn).to.change(obj, 'val').not.by(5);