chai-withintoleranceof
A chai plugin to assert that a number is within tolerance of an expected value
Installation
npm install --save-dev chai-withintoleranceof
Example Usage
var chai = ;var expect = chaiexpect; chai; // check that 515 is within tolerance of 500 +/- 5% (475 .. 525)tobe; // check that 786 is within tolerance of 1000 +30% / -70% (300 .. 1300)tobe;tobe; // check that 400 is within tolerance of 350 +15% (350 .. 402.5)tobe; // check that 500 is within tolerance of 555 -37% (349.65 .. 555)tobe; // check that -645 is within tolerance of -1000 +30% / -70% (-1300 .. -300)tobe;tobe; // Can also be used in conjunction with `length`// check that the length of 'foo' is within tolerance of 2 +/- 50% (1 .. 3)tohavelength; // check that the length of the array is within tolerance of// 2 +50% / -40% (1.2 .. 3)tohavelength; // There is also an abbreviated formtobe;
License
chai-withintoleranceof is licensed under the MIT License.