Skip to content

Commit

Permalink
isAtLeast, isAtMost assertions added to assert interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Wraithan (Chris McDonald) committed Jul 24, 2015
1 parent bad5fa7 commit 3c681e2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
38 changes: 38 additions & 0 deletions lib/chai/interface/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,25 @@ module.exports = function (chai, util) {
new Assertion(val, msg).to.be.above(abv);
};

/**
* ### .isAtLeast(valueToCheck, valueToBeAtLeast, [message])
*
* Asserts `valueToCheck` is greater than or equal to (>=) `valueToBeAtLeast`
*
* assert.isAtLeast(5, 2, '5 is greater or equal to 2');
* assert.isAtLeast(3, 3, '3 is greater or equal to 3');
*
* @name isAtLeast
* @param {Mixed} valueToCheck
* @param {Mixed} valueToBeAtLeast
* @param {String} message
* @api public
*/

assert.isAtLeast = function (val, atlst, msg) {
new Assertion(val, msg).to.be.least(atlst);
};

/**
* ### .isBelow(valueToCheck, valueToBeBelow, [message])
*
Expand All @@ -261,6 +280,25 @@ module.exports = function (chai, util) {
new Assertion(val, msg).to.be.below(blw);
};

/**
* ### .isAtMost(valueToCheck, valueToBeAtMost, [message])
*
* Asserts `valueToCheck` is less than or equal to (<=) `valueToBeAtMost`
*
* assert.isAtMost(3, 6, '3 is less than or equal to 6');
* assert.isAtMost(4, 4, '4 is less than or equal to 4');
*
* @name isAtMost
* @param {Mixed} valueToCheck
* @param {Mixed} valueToBeAtMost
* @param {String} message
* @api public
*/

assert.isAtMost = function (val, atmst, msg) {
new Assertion(val, msg).to.be.most(atmst);
};

/**
* ### .isTrue(value, [message])
*
Expand Down
18 changes: 18 additions & 0 deletions test/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,15 @@ describe('assert', function () {
}, 'expected 1 to be above 1');
});

it('atLeast', function() {
assert.isAtLeast(5, 2, '5 should be above 2');
assert.isAtLeast(1, 1, '1 should be equal to 1');

err(function() {
assert.isAtLeast(1, 3);
}, 'expected 1 to be at least 3');
});

it('below', function() {
assert.isBelow(2, 5, '2 should be below 5');

Expand All @@ -739,6 +748,15 @@ describe('assert', function () {

});

it('atMost', function() {
assert.isAtMost(2, 5, '2 should be below 5');
assert.isAtMost(1, 1, '1 should be equal to 1');

err(function() {
assert.isAtMost(3, 1);
}, 'expected 3 to be at most 1');
});

it('memberDeepEquals', function() {
assert.sameDeepMembers([ {b: 3}, {a: 2}, {c: 5} ], [ {c: 5}, {b: 3}, {a: 2} ], 'same deep members');
assert.sameDeepMembers([ {b: 3}, {a: 2}, 5, "hello" ], [ "hello", 5, {b: 3}, {a: 2} ], 'same deep members');
Expand Down

0 comments on commit 3c681e2

Please sign in to comment.