qunit-assert-compare
v1.1.0
Published
A QUnit plugin for asserting numerical comparisons like greater than, less than, etc.
Downloads
1,117
Maintainers
Keywords
Readme
qunit-assert-compare
A QUnit plugin for asserting numerical comparisons like greater than, less than, etc.
QUnit numerical comparison assertion plugin
This plugin for QUnit adds a handful of custom assertion methods to test for various numerical comparison situations:
eq
: equal toneq
: not equal tolt
: less thanlte
: less than or equal togt
: greater thangte
: greater than or equal tocompare
: sorting-style comparisons
Usage
assert.eq(num1, num2, message);
assert.neq(num1, num2, message);
assert.lt(num1, num2, message);
assert.lte(num1, num2, message);
assert.gt(num1, num2, message);
assert.gte(num1, num2, message);
assert.compare(num1, num2, expected, message);
Where:
num1
: The lefthand operandnum2
: The righthand operandmessage
: Optional message, same as for other assertionsexpected
: [ONLY used forassert.compare
!] A sorting-style return value for the numerical comparison:-1
(less than)0
(equal to)1
(greater than)
Examples
module('Example module')
test('Example unit test', function(assert) {
assert.eq(2, 2);
assert.neq(-2, 2);
assert.lt(-2, 2);
assert.lte(2, 2);
assert.gt(2, -2);
assert.gte(2, 2);
assert.compare(-2, 2, -1);
});
For more examples, refer to the unit tests.
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.
License
Copyright (c) 2015-2016 James M. Greene Licensed under the MIT license.