mirror of
https://github.com/chaijs/chai
synced 2024-11-15 08:17:14 +00:00
Add Assertion.closeTo()
method.
This commit is contained in:
parent
833a80c4d3
commit
c735d7ea04
1 changed files with 21 additions and 0 deletions
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue