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

    Interface ChangeFn

    Function signature for change assertions. Can monitor either a getter function or an object property.

    0.1.5

    • Asserts that the target function changes the return value of the getter function.

      Parameters

      • func: () => any

        A function that returns a value to monitor

      • OptionalevalMsg: MsgSource

        Optional message to display if the assertion fails

      Returns IChangeResultOp

      Result that supports .by() chaining

      let value = 1;
      const getValue = () => value;
      const addOne = () => { value++; };

      expect(addOne).to.change(getValue);
      expect(addOne).to.change(getValue).by(1);

      let count = 0;
      const getCount = () => count;
      const increment = () => { count++; };

      expect(increment).to.increase(getCount);
      expect(increment).to.increase(getCount).by(1);
    • Asserts that the target function changes the specified property of the object.

      Type Parameters

      • T

      Parameters

      • target: T

        The object containing the property to monitor

      • propName: keyof T

        The property name to monitor

      • OptionalevalMsg: MsgSource

        Optional message to display if the assertion fails

      Returns IChangeResultOp

      Result that supports .by() chaining

      const obj = { val: 10 };
      const addTwo = () => { obj.val += 2; };

      expect(addTwo).to.change(obj, 'val');
      expect(addTwo).to.change(obj, 'val').by(2);

      const obj = { count: 5 };
      const increment = () => { obj.count++; };

      expect(increment).to.increase(obj, 'count');
      expect(increment).to.increase(obj, 'count').by(1);