Asserts that the target function changes the return value of the getter function by the specified delta.
Behavior varies by assertion type:
changeBy/changesBy: Sign is ignored - only absolute value is comparedincreaseBy/increasesBy: Delta must be positive, value must increasedecreaseBy/decreasesBy: Delta should be positive (magnitude), value must decreaseA function that returns a value to monitor
The expected change amount (interpretation depends on assertion type)
OptionalevalMsg: MsgSourceOptional message to display if the assertion fails
The assertion instance for chaining
let value = 1;
const getValue = () => value;
const addFive = () => { value += 5; };
const subtractThree = () => { value -= 3; };
// changeBy - sign agnostic
expect(addFive).to.changeBy(getValue, 5); // passes (delta of 5)
expect(addFive).to.changeBy(getValue, -5); // also passes (absolute value of 5)
// increaseBy - requires positive change
expect(addFive).to.increaseBy(getValue, 5); // passes (increased by 5)
// decreaseBy - use positive delta for magnitude
expect(subtractThree).to.decreaseBy(getValue, 3); // passes (decreased by 3)
Asserts that the target function changes the specified property of the object by the specified delta.
Behavior varies by assertion type:
changeBy/changesBy: Sign is ignored - only absolute value is comparedincreaseBy/increasesBy: Delta must be positive, value must increasedecreaseBy/decreasesBy: Delta should be positive (magnitude), value must decreaseThe assertion instance for chaining
const obj = { val: 10 };
const addTwo = () => { obj.val += 2; };
const subtractFive = () => { obj.val -= 5; };
// changeBy - sign agnostic
expect(addTwo).to.changeBy(obj, 'val', 2); // passes (delta of 2)
expect(addTwo).to.changeBy(obj, 'val', -2); // also passes (absolute value of 2)
// increaseBy - requires positive change
expect(addTwo).to.increaseBy(obj, 'val', 2); // passes (increased by 2)
// decreaseBy - use positive delta for magnitude
expect(subtractFive).to.decreaseBy(obj, 'val', 5); // passes (decreased by 5)
Function signature for changeBy, increaseBy, and decreaseBy assertions. Can monitor either a getter function or an object property and validate the delta.
Important Behavior Notes:
changeBy/changesBy: Sign of delta is ignored - only absolute value mattersincreaseBy/increasesBy: Delta must be positive and value must increasedecreaseBy/decreasesBy: Delta should be positive (representing magnitude) and value must decreaseSince
0.1.5