Add Assertion.closeTo() method.

This commit is contained in:
Veselin Todorov 2012-02-25 00:04:26 +02:00
parent 833a80c4d3
commit c735d7ea04

View file

@ -902,6 +902,27 @@ Assertion.prototype.satisfy = function (matcher) {
return this;
};
/**
* # .closeTo(expected, delta)
*
* Assert that passes a truth test.
*
* expect(1).to.satisfy(function(num) { return num > 0; });
*
* @name satisfy
* @param {Function} matcher
* @api public
*/
Assertion.prototype.closeTo = function (expected, delta) {
this.assert(
(this.obj - delta === expected) || (this.obj + delta === expected)
, 'expected ' + this.inspect + ' to be close to ' + expected + ' +/- ' + delta
, 'expected ' + this.inspect + ' to not be close to ' + expected + ' +/- ' + delta);
return this;
};
/*!
* Aliases.
*/